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

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.

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.

 

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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.