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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors