Forum Discussion
Calculate difference from previous month
- 10 years ago
In this scenario, since you need to get the previous month data based on current slicing date, it's better to create a measure instead of a calculated column. Otherwise, you have to lookup previous row based on index column as ankitpatira suggested. Just create a measure like:
difference= sum(DW_Data_Salg[Inntekt])-CALCULATE(SUM(DW_Data_Salg[Inntekt]),PARALLELPERIOD(DW_Data_Salg[DATO].[Date],-1,MONTH))
Or
difference= sum(DW_Data_Salg[Inntekt])-CALCULATE(SUM(DW_Data_Salg[Inntekt]),PREVIOUSMONTH(DW_Data_Salg[DATO].[Date]))
Regards,
In this scenario, since you need to get the previous month data based on current slicing date, it's better to create a measure instead of a calculated column. Otherwise, you have to lookup previous row based on index column as ankitpatira suggested. Just create a measure like:
difference= sum(DW_Data_Salg[Inntekt])-CALCULATE(SUM(DW_Data_Salg[Inntekt]),PARALLELPERIOD(DW_Data_Salg[DATO].[Date],-1,MONTH))
Or
difference= sum(DW_Data_Salg[Inntekt])-CALCULATE(SUM(DW_Data_Salg[Inntekt]),PREVIOUSMONTH(DW_Data_Salg[DATO].[Date]))
Regards,
I have data from GitHub on the COVID cases and deaths. It has daily counts for each county in the US, for every day since January 22. I would like to be able to calculate the difference between days ("new cases" or "new deaths"). I have been able to do that in Tableau, but have not figured out how to make it happen in a calculated column in M or Dax in Power BI. In other words, for a particular County in a particular State (or for a particular FIPS Code), I need to be able to subtract the count of Confirmed Cases for Jan 22 from the same count for Jan 23. Also, if the result ends up less than zero, I need to be able to have it return 0. Any ideas? I could build a concatenated index for county, state, plus an index number, if that helps.