Forum Discussion
DAX Lookup in same table
- 4 years ago
There are a ton of different ways to do this. Here are a couple of drastically different possibilities.
FirstProcess = VAR MinDateTime = CALCULATE ( MIN ( Table1[TransDateTransTime] ), ALLEXCEPT ( Table1, Table1[Comtainer ID] ) ) RETURN CALCULATE ( SELECTEDVALUE ( Table1[Process] ), ALLEXCEPT ( Table1, Table1[Comtainer ID] ), Table1[TransDateTransTime] = MinDateTime )FirstProcess = SELECTCOLUMNS ( TOPN ( 1, FILTER ( Table1, Table1[Comtainer ID] = EARLIER ( Table1[Comtainer ID] ) ), Table1[TransDateTransTime], ASC ), "Process", Table1[Process] )
Thanks very much for your solutions, the first worked perfectly, I am slowly making the transition from Excel to Power BI, and Im unfamiliar with VAR rather than just copy and paste would you explain how the expression works so I can hopefully understand it apply the logic elsewhere when needed.
Thanks again for your help
VAR is used to calculate an expression so that it can be re-used. It's super useful for making DAX more readable than Excel formulas.
At a high level, the measure calculates the minimal datetime for that ID and then looks up the process corresponding to that minimal datetime.
Note that ALLEXCEPT is used to remove all of the filter context, except for the ID, which exists due to a context transition from the row context to filter context.
- Dazagard4 years agoRegular Visitor
Thanks for taking the time to reply and explain, I really appreciate your help