March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello,
Just learning how to use custom DAX code to create measures in Power BI. I'm trying to create a simple table visual using measures that calcualte and compare this year's results to last year's where the week numbers match. My data already has a week number column that corresponds with my company's fiscal year so I do not need to use a date column. Creating the measures for this year were easy because the data is limited to the current week. In other words, the data source doesn't contain any data for dates beyond the current week that we're in now. So for 2020 data, I created a measure for max week and called it current week. Now I need to create a measure to pull last year's data for that same week number so that I can compare results year over year. I cannot use max for last year's data because it has all 53 weeks.
This is basically how I would like to present the data:
YoY Comparision | Week 40 This Year | Week 40 Last Year |
Products Sold | 100 | 85 |
Again, my data has a week number column. I just need to find a way to get last year's data for the same week as this year's current week. Any help is very much appreciated!
Solved! Go to Solution.
Hi @jdwalker5 ,
If this solves your issue, please mark it so others can find it more easily!
Thank you,
Nathaniel
Proud to be a Super User!
This worked perfectly! Thanks for the solution. I actually used this for a separate measure to pull the week prior to max. What was odd is I had to use MAX (data[Week]) - 10 to accomplish that. Logically I would expect to be able to use MAX(data[week]) -1 but it continued to show data from the max week. My week column is data time whole number so I couldn't figure out why -10 worked but I'll take what I can get. Thanks again for your help!
Hi @jdwalker5 ,
You are very welcome!
Thank you,
Nathaniel
Proud to be a Super User!
Hi @jdwalker5 ,
If this solves your issue, please mark it so others can find it more easily!
Thank you,
Nathaniel
Proud to be a Super User!
Hi @jdwalker5 ,
So does your data have a year column?
Here is a quick table to show proof of concept.
The measure
Last Year Product Same Week =
VAR PastYear =
MAX ( Data[Year] ) - 1
VAR CurrentWeek =
MAX ( Data[Week] )
VAR _calc =
CALCULATE (
MAX ( Data[ProductSold] ),
Data[Year] = PastYear,
Data[Week] = CurrentWeek
)
RETURN
_calc
The result
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel
Proud to be a Super User!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
18 | |
15 | |
9 | |
7 |
User | Count |
---|---|
37 | |
31 | |
16 | |
16 | |
12 |