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

Weeks of inventory forecast coverage

Hi everyone, 

 

First-time poster here, I've been using PowerBI for a few months, but I have no idea how to tackle this problem. I need to calculate how many weeks will my current inventory cover for a customer forecast demand. 

 

My data source looks like this:

 

PartWk 20Wk 21Wk 22Wk 23Wk 24Wk 25Wk 26Wk 27Wk 28Wk 29Current inventory
1234604020201001050808070350
234590305006010020408020200
345630208060801080708080450
45670307020604010904050150

 

The result I want to get is the following:

 

PartWeeks of coverage 
12347
23454
34568
45674

 

The logic I'm coming up with is to sum the first week on the source, and if it is less than the current inventory, add another week, until the week cumulative sum is higher than the current inventory, then return the number of weeks added. 

 

I'm not sure if this is possible, it makes sense in my head but I have no idea how to attack this problem. If you could provide some hints on how to solve I would really appreciate it. 

 

Thanks!

 

Edit:

 

I found a way to do it in Excel, the formula is the following:

=MATCH(L2,SUBTOTAL(9,OFFSET(B2,,,,COLUMN(B2:L2)-COLUMN(B2))),1)-1

How can I translate this into PowerBI?

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @rcorrales 

 

Following steps below to achieve your requirement.

 

1.Upivot the week column, click on column Wk20-Wk29, click "Unpivot Columns", rename this result column with "Week". Don't forget to click the "Close & Apply" button.

 

4.png

2.Create columns and measure like DAX below.

 

Column: Rank = CALCULATE(COUNT(Table1[Value]),FILTER(ALLSELECTED(Table1),Table1[Part]=EARLIER(Table1[Part])&&Table1[Week]<=EARLIER(Table1[Week])))

 

Column: Cumulative_sum = CALCULATE(SUM(Table1[Value]),FILTER(ALLSELECTED(Table1),Table1[Part]=EARLIER(Table1[Part])&&Table1[Week]<=EARLIER(Table1[Week])))

 

Measure: Weeks of coverage = CALCULATE(FIRSTNONBLANK(Table1[Rank],1)-1,FILTER(ALLSELECTED(Table1),Table1[Part]=MAX(Table1[Part])&&[Cumulative_sum]>Table1[Current inventory]))

 

3.Result:

 

5.png

 

 

 

 

You can download my test pbix: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EY3frJErIPtMjksEOS... .

 

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

2 REPLIES 2
v-xicai
Community Support
Community Support

Hi @rcorrales 

 

Following steps below to achieve your requirement.

 

1.Upivot the week column, click on column Wk20-Wk29, click "Unpivot Columns", rename this result column with "Week". Don't forget to click the "Close & Apply" button.

 

4.png

2.Create columns and measure like DAX below.

 

Column: Rank = CALCULATE(COUNT(Table1[Value]),FILTER(ALLSELECTED(Table1),Table1[Part]=EARLIER(Table1[Part])&&Table1[Week]<=EARLIER(Table1[Week])))

 

Column: Cumulative_sum = CALCULATE(SUM(Table1[Value]),FILTER(ALLSELECTED(Table1),Table1[Part]=EARLIER(Table1[Part])&&Table1[Week]<=EARLIER(Table1[Week])))

 

Measure: Weeks of coverage = CALCULATE(FIRSTNONBLANK(Table1[Rank],1)-1,FILTER(ALLSELECTED(Table1),Table1[Part]=MAX(Table1[Part])&&[Cumulative_sum]>Table1[Current inventory]))

 

3.Result:

 

5.png

 

 

 

 

You can download my test pbix: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EY3frJErIPtMjksEOS... .

 

Best Regards,

Amy

 

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

 

Thank you so mucho @v-xicai. Sorry it took me this long to reply, I was out of the office and I'm just catching up. 

 

I'll study this solution so I can figure out the logic and the coding behind it, but this accomplishes the goal I was looking for. I really appreciate your quick response!

Helpful resources

Announcements
Vote for T-Shirt Design

Power BI T-Shirt Design Challenge 2023

Vote for your favorite t-shirt design now through March 28.

March 2023 Update3

Power BI March 2023 Update

Find out more about the March 2023 update.

March Events 2023A

March 2023 Events

Find out more about the online and in person events happening in March!

Top Solution Authors