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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Calculate Month of Supply, based on latest sell out

Hi, 

 

I would really appreciate your help with the below question. I am very new to Power BI and I can't seem to find a solution for this anywhere. 

I am looking to Calculate the Month of Supply=Latest week stock/ sum of last 4 weeks of Sales. 

 

Below is an example of Raw data I have, in this case, I would like to use Wk 29 stock (57)/ Sum of Week 26,27,28,29 Sales

 

This data will be updated every week, on Wk 30, the formula should be = Wk30 stock/sum of week 27,28,29,30 sales

 

Distributor/RetailerYearWkPosting DateRazer Pdt codeItem/Service DescriptionSalesstock
Customer 12021277/11/20212043Product A650
Customer 12021277/11/20212043Product A2868
Customer 12021287/18/20212043Product A247
Customer 12021287/18/20212043Product A172
Customer 12021297/25/20212043Product A957

 

Thanks in advance 

 

 

3 REPLIES 3
v-angzheng-msft
Community Support
Community Support

Hi, @Anonymous 

 

Try to create a measure like this:

_MonthOfSupply = 
var _last4W=
CALCULATE(
    SUM('Table'[Sales]),
    FILTER(ALL('Table'),'Table'[Wk]>=MAX('Table'[Wk])-4&&'Table'[Wk]<MAX('Table'[Wk])))
var _stock=MAX('Table'[stock])
return DIVIDE(_stock,_last4W)

Result:

vangzhengmsft_0-1627885797547.png

Please refer to the attachment below for details

 

 

Hope this helps.

 

Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Create a date table and there create week related columns 

 

new columns
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

 

measures
This Week = CALCULATE(sum('Stock'[stock]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))

 

 

Last 4 weeks sales= CALCULATE(sum('Table'[sales]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-4 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

Ratio = divide([This week], [Last 4 weeks sales])

 

 

 

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-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8

Anonymous
Not applicable

Hi @amitchandak 

 

Thanks for your help I managed to calculate the Month of Supply. I am now trying to display my matrix as a separate table from the main table. do you have any idea how i can do that?

you can see the below photo for your reference, rather than the Month of supply showing under Week, it should show 1 column as of to date

CelineHo_0-1628060615608.png

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.