calculated columns - Min value with GROUP BY in Power BI Desktop -


id  datetime             new_column           datetime_rankx 1   12.01.2015 18:10:10  12.01.2015 18:10:10  1 2   03.12.2014 14:44:57  03.12.2014 14:44:57  1 2   21.11.2015 11:11:11  03.12.2014 14:44:57  2 3   01.01.2011 12:12:12  01.01.2011 12:12:12  1 3   02.02.2012 13:13:13  01.01.2011 12:12:12  2 3   03.03.2013 14:14:14  01.01.2011 12:12:12  3 

i want make new column, have minimum datetime value each row in group id.

how in power bi desktop using dax query?

use expression:

newcolumn =   calculate(     min(       table[datetime]),       filter(table,table[id]=earlier(table[id])    )   ) 

in power bi using table data produce this:

enter image description here


update: explanation , earlier function usage.

basically, earlier function give access values of different row context.

when use calculate function creates row context of whole table, theoretically iterates on every table row. same happens when use filter function iterate on whole table , evaluate every row against filter condition.

so far have 2 row contexts, row context created calculate , row context created filter. note filter use earlier access calculate's row context. having said that, in our case every row in outer (calculate's row context) filter returns set of rows correspond current id in outer context.

if have programming background give sense. similar nested loop.

hope python code points main idea behind this:

outer_context = ['row1','row2','row3','row4'] inner_context = ['row1','row2','row3','row4']   outer_row in outer_context:     inner_row in inner_context:         if inner_row == outer_row: #this line filter , earlier              #calculate min datetime using filtered rows             ...             ... 

update 2: adding ranking column.

to desired rank can use expression:

rankcolumn =    rankx(     calculatetable(table,allexcept(table,table[id]))     ,table[datetime]     ,hoja1[datetime]     ,1  )   

this table rank column:

enter image description here

let me know if helps.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -