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 everyone,
I have a report that updates data monthly thanks to the following measure:
Solved! Go to Solution.
I usually include a Date dimension with several attributes. One nice attribute is [Months Back] and is defined as the number of months between the date in question and today. So for any date in November 2020, that value would be 2.
Try DATEDIFF in DAX. DATEDIFF function (DAX) - DAX | Microsoft Docs
I have done this either in SQL with DATEADD and GETDATE() functions, or Power Query, or even in DAX. I will leave it to you to choose what works best. But since it is always in reference to today, the numbers are dynamic.
You can then write the Measure as:
Two Months Ago = CALCULATE ( Sum ( [column] ), Dates[Months Back] = 2 )
Proud to be a Super User! | |
@Nick2358 , Chnage it like
2020_2_Months_Ago =
var current_month = eomonth(TODAY(),-2)
return CALCULATE(SUM('Conso Bdgt 2020'[SUM]), FILTER('Dates', eomonth('Dates'[Date],0) = current_month))
But my advice should be use datesmtd or previousmonth
previous to previous month value = CALCULATE(sum(''Table''[total hours value]),previousmonth(dateadd('Date'[Date],-1,MONTH)))
previous month value = CALCULATE(sum('Table'[total hours value]),previousmonth('Date'[Date]))
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
2nd last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-2,MONTH)))
also refer my video Why Time intellignce fails- https://www.youtube.com/watch?v=OBf0rjpp5Hw
Hi @Nick2358 ,
Try to create a measure like so:
2_Months_Ago =
CALCULATE (
SUM ( 'Conso Bdgt 2020'[SUM] ),
DATESINPERIOD ( 'Dates'[Date], MAX ( 'Date'[Date] ), - 2, MONTH )
)
Best regards
Icey
If this post helps, then consider Accepting it as the solution to help other members find it faster.
Hi @Nick2358 ,
Try to create a measure like so:
2_Months_Ago =
CALCULATE (
SUM ( 'Conso Bdgt 2020'[SUM] ),
DATESINPERIOD ( 'Dates'[Date], MAX ( 'Date'[Date] ), - 2, MONTH )
)
Best regards
Icey
If this post helps, then consider Accepting it as the solution to help other members find it faster.
Sorry for the delay I had to apply it to my whole dashboard and make sure it works.
I tried all of them and they all worked so I accepted all of your solutions.
Thanks for your help,
Nick,
@Nick2358 , Chnage it like
2020_2_Months_Ago =
var current_month = eomonth(TODAY(),-2)
return CALCULATE(SUM('Conso Bdgt 2020'[SUM]), FILTER('Dates', eomonth('Dates'[Date],0) = current_month))
But my advice should be use datesmtd or previousmonth
previous to previous month value = CALCULATE(sum(''Table''[total hours value]),previousmonth(dateadd('Date'[Date],-1,MONTH)))
previous month value = CALCULATE(sum('Table'[total hours value]),previousmonth('Date'[Date]))
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
2nd last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-2,MONTH)))
also refer my video Why Time intellignce fails- https://www.youtube.com/watch?v=OBf0rjpp5Hw
I usually include a Date dimension with several attributes. One nice attribute is [Months Back] and is defined as the number of months between the date in question and today. So for any date in November 2020, that value would be 2.
Try DATEDIFF in DAX. DATEDIFF function (DAX) - DAX | Microsoft Docs
I have done this either in SQL with DATEADD and GETDATE() functions, or Power Query, or even in DAX. I will leave it to you to choose what works best. But since it is always in reference to today, the numbers are dynamic.
You can then write the Measure as:
Two Months Ago = CALCULATE ( Sum ( [column] ), Dates[Months Back] = 2 )
Proud to be a Super User! | |
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 |
---|---|
113 | |
100 | |
78 | |
76 | |
52 |
User | Count |
---|---|
144 | |
109 | |
108 | |
88 | |
61 |