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.
Hi guys,
I have trouble getting the same period last year (and years before) YTD metrics. I tried dateadd, totalytd, etc functions, but I can't get desired results. I hope to get some help here.
So the issue of the methods I tried always gives me the total amount to the end of the month of last year or years before.
For example, today is Nov 7, so YTD is Jan 1 to Nov 7. The accumulated sales or whatever count ends today. But the result of the previous year ends on Nov 30.
What I want and would like to present in a line chart is that:
X axis is month (Jan to Nov), and the legend is year (2020, 2021, and 2022)
Accumulated sales are from Jan 1 to Nov 7, 2020 vs Jan 1 to Nov 7, 2021 vs Jan 1 to Nov 7, 2022
But now I'm getting the line chart showing the metric from Jan 1 to Nov 30, 2020 vs Jan 1 to Nov 30, 2021 vs Jan 1 to Nov 7, 2022, making the gap in Nov very large.
Appreciate all input! Thanks guys!
@kimh , Try measures like
YTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , MAXX(allselecetd('Date'), 'Date'[Date]))
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))
LYTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , MAXX(allselecetd('Date'), 'Date'[Date]))
var _max = Date(Year(_max1)-1, Month(_max1), Day(_max1))
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))
LYTD last to last =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , MAXX(allselecetd('Date'), 'Date'[Date]))
var _max = Date(Year(_max1)-2, Month(_max1), Day(_max1))
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))
Hi amitchandak,
Thank you so much for your reply. You created three measures which are exactly what I want. Is it possible to put them into a line chart, so that it will show the difference in accumulated sales of each month?
So I think the Var here should be year. Once I put year into legend, the chart should show the accumulated sales for the three year to date (Nov 7). However, what I got for the accumulated sales of the two past years is to the end of Nov as the X asix is month.
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 |
---|---|
41 | |
21 | |
21 | |
14 | |
14 |
User | Count |
---|---|
42 | |
39 | |
33 | |
19 | |
18 |