Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello,
I need to check next status(st)=open for an id and then update the current row with a flag=A. I tried with earlier function but unable to get the expected result. Please suggest how to implement using DAX.
id,st,cdate,flag
1,st,jan17,A
1,open,feb17,NULL
Thank you
Solved! Go to Solution.
In this scenario, you can create a measure for next date first.
NextDate = CALCULATE ( MIN ( 'Table'[Date] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[Id] ), 'Table'[Date] > MAX ( 'Table'[Date] ) ) )
Then create a calculated column to lookup the corresponding Status based on NextDate.
NextStatus = LOOKUPVALUE ( 'Table'[Status], 'Table'[Date], [NextDate], 'Table'[Id], 'Table'[Id] )
Regards,
Hi @aj1107,
What happens to the previous row? Should the flag be changed to NULL from A in that?
Prateek Raina
Hi
I've added few more records. whenever next st is open for the ID set then update current row as A. if the next st is <>open or no more records for the id Set (last row of each id) then NULL.
id,st,cdate
1,close,jan17,A
1,open,feb17,NULL
1,close,mar17,A
1,open,apr17,NULL
2,st,jan17,NULL
3,st,jan17,A
3,open,Feb17,NULL
Hi @aj1107,
How about below DAX:
Flag = IF(Table1[St] = "Open","NULL","A")
Gives below result:
Does it work for you?
Prateek Raina
My bad. I missed the logic . Actually in flag column i need to bring the next status to current row.(similar to lead function in sql) Please find below.
id,st,cdate
1,open,jan17,Open
1,open,feb17,open
1,open,mar17,close
1,close,apr17,NULL
2,st,jan17,NULL
3,open,jan17,close
3,close,Feb17,NULL
In this scenario, you can create a measure for next date first.
NextDate = CALCULATE ( MIN ( 'Table'[Date] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[Id] ), 'Table'[Date] > MAX ( 'Table'[Date] ) ) )
Then create a calculated column to lookup the corresponding Status based on NextDate.
NextStatus = LOOKUPVALUE ( 'Table'[Status], 'Table'[Date], [NextDate], 'Table'[Id], 'Table'[Id] )
Regards,
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
99 | |
83 | |
70 | |
60 |
User | Count |
---|---|
150 | |
115 | |
104 | |
89 | |
65 |