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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

How to compare a metric versus last week or month

Hi

I would like to compare my weekly and monthly sales with the previous week or month. How can I do it?

Imagine my data source looks like this

2019-08-16 23_36_44-Book1 - Excel.png

 

And my final goal is to be able to build a matrix like this

2019-08-16 23_43_02-.png

 

How can I do this?

Last. How can I compare versus a same week or same month last year?

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You can create calendar table first of all, create relationship between your data table and calendar table on date field, then create measures like DAX below. You can create for Month sale in the similar template (see the red mark).

 

DateDim= CALENDARAUTO()
 
CW Sale= CALCULATE(SUM(Table1[sales]),FILTER(ALLSELECTED(Table1),YAER(Table1[Date]) =YEAR(MAX(Table1[Date]))&&Table1[WeekNum] =MAX(Table1[WeekNum])))
 
LW Sale = CALCULATE(SUM(Table1[Sales]),DATEADD('DateDim'[Date],-7,DAY))
 
Vs LW %= IF([LW]<>BLANK(),DIVIDE([CW]-[LW],[LW]),BLANK())

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
v-xicai
Community Support
Community Support

Hi  @Anonymous ,

 

Does that make sense? If so, kindly mark the proper reply as a solution to help others having the similar issue and close the case. If not,  let me know and I'll try to help you further.

 

Best regards

Amy

v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You can create calendar table first of all, create relationship between your data table and calendar table on date field, then create measures like DAX below. You can create for Month sale in the similar template (see the red mark).

 

DateDim= CALENDARAUTO()
 
CW Sale= CALCULATE(SUM(Table1[sales]),FILTER(ALLSELECTED(Table1),YAER(Table1[Date]) =YEAR(MAX(Table1[Date]))&&Table1[WeekNum] =MAX(Table1[WeekNum])))
 
LW Sale = CALCULATE(SUM(Table1[Sales]),DATEADD('DateDim'[Date],-7,DAY))
 
Vs LW %= IF([LW]<>BLANK(),DIVIDE([CW]-[LW],[LW]),BLANK())

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

MattAllington
Community Champion
Community Champion

You need to use time intelligence functions. Read my article here https://exceleratorbi.com.au/dax-time-intelligence-beginners/


* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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