Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and a 50 percent discount on exams.
Get startedEarn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi I have read a few posts on this issue, but I could not get anything to work properly.
I have the following table and want to create a measure to find the difference from the current Selected month to the previous month. The following works, but the problem is that I am having problems making the date "MAY" dynamic to refer to the previous month when the user changes the date filter on the table below.
Sales difference from previous month =
VAR __BASELINE_VALUE =
CALCULATE(
SUM('Tbl_sales’[Sales]),
'DIM_Date'[Date].[Month] IN { "May" },
ALL('DIM_Date'[Date].[MonthNo])
)
VAR __MEASURE_VALUE = SUM('Tbl_sales’[Sales]),
RETURN
IF(NOT ISBLANK(__MEASURE_VALUE), __MEASURE_VALUE - __BASELINE_VALUE)
Thank you!
Solved! Go to Solution.
Hi
Use the below code instead of the "MAY" :
Hi,
Please check the below picture and the attached pbix file.
I tried to create a sample pbix file like below, and I suggest having a calendar table like below.
I hope the below sample can provide some ideas on how to create a solution for your dataset.
Sales measure: =
SUM( Sales[Sales] )
Sales Previous month: =
CALCULATE( [Sales measure:],
DATEADD( 'Calendar'[Date], -1, MONTH )
)
Sales diff: =
IF( not ISBLANK( [Sales measure:] ), [Sales measure:] - [Sales Previous month:] )
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi,
Please check the below picture and the attached pbix file.
I tried to create a sample pbix file like below, and I suggest having a calendar table like below.
I hope the below sample can provide some ideas on how to create a solution for your dataset.
Sales measure: =
SUM( Sales[Sales] )
Sales Previous month: =
CALCULATE( [Sales measure:],
DATEADD( 'Calendar'[Date], -1, MONTH )
)
Sales diff: =
IF( not ISBLANK( [Sales measure:] ), [Sales measure:] - [Sales Previous month:] )
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Tried this as well and it worked great! thank you!
Hi
Use the below code instead of the "MAY" :
that worked GREAT! thank you and others on the community!
Hey @cjcj ,
this article contains almost everything you need to know about time/date calculations: Time patterns – DAX Patterns
Check the time intelligence function PREVIOUSMONTH: PREVIOUSMONTH – DAX Guide
Hopefully, this will provide some information on how to tackle your challenge.
Regards,
Tom