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
manoranjan
Frequent Visitor

Stock Cover Calculation Measure

Hi All,

 

I have Weekly data of Stock and Planned Sales. For any given week, I want to Calculate the Stock Cover.

Stock Cover = How many weeks of Sales I can cover with the Current Stock.

 

My Data is like this

Week

Stock

Sales Plan

W01

100

40

W02

120

40

W03

130

40

W04

110

40

W05

80

40

W06

100

50

W07

120

50

 

 

In the above example, Week 1 Stock = 100 units and with that I can cover my sales for next 2.5 weeks. ( In other words I can sell w2, w3, and 0.5 of w4).

 

I want to build a measure that can show below table

Week

Stock

Sales Plan

Stock Cover

W01

100

40

2.5

W02

120

40

3.0

W03

130

40

3.2

W04

110

40

2.6

 

Please help, how to calculate the Stock Cover Measure.

 

Thanks in advance.

 

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@manoranjan,

 

You may check the following DAX.

Column =
VAR s = Table1[Stock]
VAR w = Table1[Week]
VAR t =
    FILTER ( Table1, Table1[Week] > w )
VAR t2 =
    ADDCOLUMNS (
        t,
        "total", SUMX (
            FILTER ( t, Table1[Week] <= EARLIER ( Table1[Week] ) ),
            Table1[Sales Plan]
        )
    )
RETURN
    IF (
        COUNTROWS ( FILTER ( t2, [total] >= s ) )
            > 0,
        COUNTROWS ( FILTER ( t2, [total] < s ) )
            + DIVIDE (
                s
                    - MAXX ( TOPN ( 1, FILTER ( t2, [total] < s ), Table1[Week], DESC ), [total] ),
                MAXX (
                    TOPN ( 1, FILTER ( t2, [total] >= s ), Table1[Week], ASC ),
                    Table1[Sales Plan]
                )
            )
    )
Community Support Team _ Sam Zha
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

12 REPLIES 12

Helpful resources

Announcements
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.