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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Measure Calculation percentage difference of current week sales by avg of its previous sales

Hi Everyone, I have a data in below format

Storeweeksales
X9555
X8647
X7889
X6846
X5558
X4993
Y9736
Y8746
Y7927
Y6601
Y5509
Y4589
Z9964
Z8578
Z7833
Z6992
Z5558
Z4739

and I want to create a summary table (using power BI table visual) as per blow

 current weekPrevious Avg%diff
Store X555786.60-29.4%
Store Y736674.409.1%
Store Z964740.0030.3%

How can I do this more efficiently so that each week I don't have to manually filter anything .e.g., if week 10 sales are added then current week should be moved to week 10 and all previous weeks should be included in Previous week avg.

How to include this automation in measure % diff and other columns where I am currently using filters

Your help will be appreciated.

Thanks.

3 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

Seems like:

 

Current Week Measure =
  VAR __Store = MAX('Table'[Store])
  VAR __MaxWeek = MAXX(FILTER('Table',[Store] = __Store),[week])
RETURN
  MAXX(FILTER('Table',[Store] = __Store && [week] = __MaxWeek),[sales])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Greg_Deckler
Super User
Super User

For previous average:

 

Previous Avg Measure =
  VAR __Store = MAX('Table'[Store])
  VAR __MaxWeek = MAXX(FILTER('Table',[Store] = __Store),[week])
RETURN
  AVERAGEX(FILTER('Table',[Store] = __Store && [week] <> __MaxWeek),[sales])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Greg_Deckler
Super User
Super User

For % diff:

%Diff Measure = 
  ([Current Week Measure] - [Previous Avg Measure]) / [Previous Avg Measure]


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

For % diff:

%Diff Measure = 
  ([Current Week Measure] - [Previous Avg Measure]) / [Previous Avg Measure]


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

For previous average:

 

Previous Avg Measure =
  VAR __Store = MAX('Table'[Store])
  VAR __MaxWeek = MAXX(FILTER('Table',[Store] = __Store),[week])
RETURN
  AVERAGEX(FILTER('Table',[Store] = __Store && [week] <> __MaxWeek),[sales])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

Seems like:

 

Current Week Measure =
  VAR __Store = MAX('Table'[Store])
  VAR __MaxWeek = MAXX(FILTER('Table',[Store] = __Store),[week])
RETURN
  MAXX(FILTER('Table',[Store] = __Store && [week] = __MaxWeek),[sales])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks Greg, worked like a charm 🙂

Awesome! 🙂


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
GrahamKnowles
Resolver I
Resolver I

Assuming you are using just a numbered week rather than a date table, you could add a custom columns to your table to achieve this.

 

So create a custom column as:

Latest Week = MAX(Table[week])

 

then a second column to dictate if a line is in the current week or last week:

IsCurrentWeek = if(Table[week]=Table[Latest Week],"Current",if(Table[week]=(Table[Latest Week]-1),"Last Week","Not Current")
 
You can then make further calculations off these results.
 
Does this help?
 
amitchandak
Super User
Super User

@Anonymous 

Refer this file , How I creates Week , last/prior week using Rank. In case you have only one year data you can use Week

https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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