Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be 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

Reply
jdwalker5
Helper II
Helper II

Need measure to calculate if last year's week number equals this year's week number

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 ComparisionWeek 40 This YearWeek 40 Last Year
Products Sold10085

 

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!

1 ACCEPTED SOLUTION
Nathaniel_C
Super User
Super User

Hi @jdwalker5 ,
If this solves your issue, please mark it so others can find it more easily!

 

Thank you,

 

Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
jdwalker5
Helper II
Helper II

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Nathaniel_C
Super User
Super User

Hi @jdwalker5 ,
If this solves your issue, please mark it so others can find it more easily!

 

Thank you,

 

Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Nathaniel_C
Super User
Super User

Hi @jdwalker5 ,

 

 

So does your data have a year column?


Here is a quick table to show proof of concept.
last1.PNG
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
last.PNG


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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.