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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX to calculate Week Stock

Hi,

I need to pedict the future week stock for each material.

I am able to create the table for the qty receivable from suppliers in the corresponding week, but not able to find the solution to calculate the Week Stock.

I have two tables:

Table 1 showing records for Receivable quantities in the below format shown below:

Week Num  COO       Plant        Material   Suppliers                 PO Qty      Weeks

27JP10111India1970
27JP10111Japan1870
27JP10111Germany1020
27JP10111AFFL1920
27JP10111FRIng1740
27JP101113rd Party4860
27JP10112India00
27JP10112Japan00
27JP10112Germany00
27JP10112AFFL00
27JP10112FRIng00
27JP101123rd Party00
27JP10113India00
27JP10113Japan00
27JP10113Germany00
27JP10113AFFL00
27JP10113FRIng00
27JP101133rd Party00
27IN10111India1860
27IN10111Japan1760
27IN10111Germany1320
27IN10111AFFL1240
27IN10111FRIng1350
27IN101113rd Party4940
27IN10112India1040
27IN10112Japan1280
27IN10112Germany1840
27IN10112AFFL1880
27IN10112FRIng1570
27IN101123rd Party4160
27IN10113India00
27IN10113Japan00
27IN10113Germany00
27IN10113AFFL00
27IN10113FRIng00
27IN101133rd Party00
27KR10111India1460
27KR10111Japan1900
27KR10111Germany1820
27KR10111AFFL1790
27KR10111FRIng1010
27KR101113rd Party5180
27KR10112India1470
27KR10112Japan1870
27KR10112Germany1940
27KR10112AFFL1040
27KR10112FRIng1070

 

- This list can be appended with different combination of Week Num, COO, Plant, Material & Suppliers.

- 3rd Party calculation is Sum(India+Japan+Germany)

 

Table 2 showing the inventory, weekly consumption and the delayed PO quantities for all the material across different plants and Country.

COO             Plant     Material  Curr Inv    WklyUsg  Late PO

JP10111395357231
JP10112000
JP10113000
IN10111116327147
IN1011213526757
IN10113000
KR10111999152
KR10112180181134
KR101134619589

 

I want to calculate the weekly Stock after every week (27, 28, 29, 30...........)

Steps to calculate Weekly stock are:

Step1: Calculate Total Receivables from Suppliers (Sum(AFFL, FRIng & 3rd Party), i.e. a selective sum of the PO Qty for the Suppliers.  This issue is resolved.

Step2: Week 27 (current week) Stock Calculation is Sum(PO Qty receivable in Step 1 + Current Inv + Late PO) - Weekly Usage

- Step3: Week 28 and onwards (next week and onwards) - Sum(PO receivable qty from the supplier in the corresponding month + Late PO + Week Stock of previous month, eg. Week 27 stock in this case) - weekly usage.

Attached the expected Report layout.Expected Report LayoutExpected Report Layout

4 REPLIES 4
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

This is my file.

 

Best Regards

Maggie

Anonymous
Not applicable

Hi @v-juanli-msft 

Thanks for your file. But this does not resolve my problem. As per my data table the Weekly Stock for Week 27 is correct, but the subsequent weeks are wrong as it is using the same Current Inventory for other weeks as well. In this case the week 28 and onwards it should use the week stock as the current inventory for the next week stock calculation.

v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Merge column in Power query to create a new column [id] in both tables.

Then create a relationship between two tables.

Capture10.JPG

Capture11.JPG

Create measures

current sum =
CALCULATE (
    SUM ( 'Table 1'[PO Qty] ),
    FILTER ( 'Table 1', 'Table 1'[Suppliers] IN { "AFFL", "FRIng", "3rd Party" } )
)


previous sum =
CALCULATE (
    SUM ( 'Table 1'[PO Qty] ),
    FILTER (
        ALLSELECTED ( 'Table 1' ),
        'Table 1'[Suppliers] IN { "AFFL", "FRIng", "3rd Party" }
            && 'Table 1'[Suppliers] = MAX ( 'Table 1'[Suppliers] )
            && 'Table 1'[id] = MAX ( 'Table 1'[id] )
            && 'Table 1'[Week Num]
                = MAX ( 'Table 1'[Week Num] ) - 1
    )
)

Measure 2 =
VAR c1 =
    LOOKUPVALUE ( 'Table 2'[Curr Inv], 'Table 2'[id], MAX ( 'Table 1'[id] ) )
VAR w1 =
    LOOKUPVALUE ( 'Table 2'[WklyUsg], 'Table 2'[id], MAX ( 'Table 1'[id] ) )
VAR l1 =
    LOOKUPVALUE ( 'Table 2'[Late PO], 'Table 2'[id], MAX ( 'Table 1'[id] ) )
RETURN
    SWITCH (
        MAX ( [Week Num] ),
        27, [current sum] + c1 + l1 - w1,
        [current sum] + [previous sum] + c1 + l1 - w1
    )

 

Best Regards
Maggie
Community Support Team _ Maggie Li
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 , Please see in My blog on week can help you. The only thing you can not do in power BI, Calculate July and use July to build August. You have to build a cumulative measure.

 

https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.