cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Yo_thescooter
Frequent Visitor

% Difference from previous week

Hi all,

 

I have columns, country, customer, product_group, model_id, week, year, price, and sales (#). I have several countries, and each country has several product_groups, and each product_group has several model_ids. I have 52 weeks for 2021 and will continue like that for 2022, 2023 etc. Prices for model_ids differ. 

 

I need to find the %difference change from the previous week for each row for price and sales (#). 

 

Each row needs to be unique since there are several variables (country, customer, etc.) 

You can check a dummy screenshot below.

 

How can I do this in PowerBI? Having an extra two columns which will be like "% change price week-over-week" and "% change sales # week-over-week"

 

Thank you!

 

PowerBIHElp.png

 

1 ACCEPTED SOLUTION
mangaus1111
Solution Sage
Solution Sage

Hi @Yo_thescooter ,

see my pbi file. I have splitted the column Week in 2 columns (week and year) in power query.

https://1drv.ms/u/s!Aj45jbu0mDVJi0DlD5sZpcgVxDjE?e=khhDbs

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

6 REPLIES 6
mangaus1111
Solution Sage
Solution Sage

Hi @Yo_thescooter ,

see my pbi file. I have splitted the column Week in 2 columns (week and year) in power query.

https://1drv.ms/u/s!Aj45jbu0mDVJi0DlD5sZpcgVxDjE?e=khhDbs

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

Hey Mangaus,

 

This looks promising. I will try it now. As I can see in the measure you created, you concatenated the columns to create a unique column. In that way, the calculations will be correct even if I have 1000 rows, right? 

Also, can you give me a solution for Week 1 and Week 52 issue? 

Hi @Yo_thescooter ,

I have splitted the column [report_date_week] in 2 columns, I have not done any concatenation.

Try if it works in your model.

It worked the way you did, but for the % to work, I have to have all the columns in the table, which is fine. But some tables will only have year and week, for example. And I will be looking for Avg. Price, for example. 

I tried to work on your script but couldn't manage 😕 Can you help?

 

I created Avg. Price measure as follows; 

Avg. Price = AVERAGE(Sheet1[Consumer Price])

 

Yo_thescooter_0-1667905695308.pngYo_thescooter_1-1667905729967.png

 

Let me know if anyone has any idea how to do it please

amitchandak
Super User
Super User

@Yo_thescooter , you need have date/week table with week rank joined to you table

 

Have these new columns in Date Table, Week Rank is Important in Date/Week Table
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format
WeekDay = weekday([Date])

 

These measures can help


This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8



!! Microsoft Fabric !!
Microsoft Power BI Learning Resources, 2023 !!
Learn Power BI - Full Course with Dec-2022, with Window, Index, Offset, 100+ Topics !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!

Helpful resources

Announcements
May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Submit your Data Story

Data Stories Gallery

Share your Data Story with the Community in the Data Stories Gallery.

Top Solution Authors