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, everybody,
I am a newer in DAX so maybe my question has a simple answer, but I have been struggling with it for so long and I do not find it.
I want to calculate the %YoY variation of a given meassure but not between two correlative years but every year (2020, 2021, 2022 when it comes) over one specific year (2019): %2020o2019, %2021o2019, %2022o2019 ...
If we look at the DAX code of Quick Meassure of %YoY, we can see that the Var _PREV_YEAR is defined like that:
The problem is that, with that code, what I have in return is a table containing a column of dates, for every year, with the TOTAL value from 2019 in every month (DAX does not evaluate the context of every month, I guess). I would like to write a code that can return for every year, month to month, the variation against 2019; for instances, in the year 2020, the variation january2020vs january2019, february2020 vs february2019, march2020 vs march2019etc, and in 2021, the variation january2021vs january2019, february2021 vs february2019, march2021 vs march2019; and so on with every year in the future.
For some reason that I do not undestand, with DATESBETWEEN, DAX does not evaluate the context of the months filtered (whereas it does it with DATEADD)
Solved! Go to Solution.
@JFS , You can get year 2019 like
M2019=
CALCULATE(
[meassure],
year('Date'[Date])=2019)
or
M2019=
CALCULATE(
[meassure],filter(all(Date[Year]), 'Date'[year]=2019))
this case if year is in visual, diff = [measure] -[M2019]
for other you can use time intelligence
examples
Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))
Hi @JFS ,
Glad that your problem has been solved, please mark the correct reply as the standard answer to help the other members find it more quickly.Thanks in advance for your kind cooperation!
Hope it helps,
Community Support Team _ Caitlyn
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Done!
Than you very much, @amitchandak !
It works with this chunk, from what you have posted (in blue )
@JFS , Yes , all is doing that.
Also, try to avoid using date hierarchy from date Table, once mark it as date table you will not get that
refer this for filter in calculate
http://dataap.org/blog/2019/04/22/difference-between-calculate-with-and-without-filter-expression/
Thanks again for the comment, @amitchandak and for the link. They are very useful.
@JFS , You can get year 2019 like
M2019=
CALCULATE(
[meassure],
year('Date'[Date])=2019)
or
M2019=
CALCULATE(
[meassure],filter(all(Date[Year]), 'Date'[year]=2019))
this case if year is in visual, diff = [measure] -[M2019]
for other you can use time intelligence
examples
Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))
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 |
---|---|
109 | |
96 | |
77 | |
66 | |
53 |
User | Count |
---|---|
144 | |
105 | |
102 | |
89 | |
63 |