Forum Discussion
Difference column from a match lookup?
- 6 years ago
hi DH102
You need to knowledge that DAX is used to create a new Calculate Column/Table/Measure.
https://docs.microsoft.com/en-us/power-bi/transform-model/desktop-tutorial-create-calculated-columns
M code is used in power query to create a custom column
https://community.powerbi.com/t5/Desktop/Dax-or-M-Language/td-p/136827
Then you could use this dax formula to create a new column
Difference from previous run = VAR previousdate= CALCULATE(MAX('Table'[Date]),FILTER('Table', [Date]<EARLIER([date]) && [Product]=EARLIER([Product])&& [item]=EARLIER([item]))) return 'Table'[% Usage of item]-CALCULATE(SUM('Table'[% Usage of item]),FILTER('Table',[date]=previousdate && [Product]=EARLIER([Product])&& [item]=EARLIER([item])))or
Difference from previous run 2 = VAR previousdate= CALCULATE(MAX('Table'[Date]),FILTER('Table', [Date]<EARLIER([date]) && [Product]=EARLIER([Product])&& [item]=EARLIER([item]))) return IF(ISBLANK(previousdate),BLANK(),'Table'[% Usage of item]-CALCULATE(SUM('Table'[% Usage of item]),FILTER('Table',[date]=previousdate && [Product]=EARLIER([Product])&& [item]=EARLIER([item]))))Regards,
Lin
hi DH102
You need to knowledge that DAX is used to create a new Calculate Column/Table/Measure.
https://docs.microsoft.com/en-us/power-bi/transform-model/desktop-tutorial-create-calculated-columns
M code is used in power query to create a custom column
https://community.powerbi.com/t5/Desktop/Dax-or-M-Language/td-p/136827
Then you could use this dax formula to create a new column
Difference from previous run =
VAR previousdate= CALCULATE(MAX('Table'[Date]),FILTER('Table', [Date]<EARLIER([date]) && [Product]=EARLIER([Product])&& [item]=EARLIER([item]))) return
'Table'[% Usage of item]-CALCULATE(SUM('Table'[% Usage of item]),FILTER('Table',[date]=previousdate && [Product]=EARLIER([Product])&& [item]=EARLIER([item])))
or
Difference from previous run 2 =
VAR previousdate= CALCULATE(MAX('Table'[Date]),FILTER('Table', [Date]<EARLIER([date]) && [Product]=EARLIER([Product])&& [item]=EARLIER([item]))) return
IF(ISBLANK(previousdate),BLANK(),'Table'[% Usage of item]-CALCULATE(SUM('Table'[% Usage of item]),FILTER('Table',[date]=previousdate && [Product]=EARLIER([Product])&& [item]=EARLIER([item]))))
Regards,
Lin