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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
eechever
Frequent Visitor

Inventory Projection

Hi, everyone.

I've been working on this problem for a week and can't find a solution. 

I have three products A, B, and C with the following information:
Product A: Current Stock Quantity 163

MonthYearNumMonthYearInc_Shipment_QtySalesForecast_Qty
Nov-2224274400115
Dec-2224275 108
Jan-2324276 93
Feb-2324277200110
Mar-2324278 132
Apr-2324279 131

 

Product B: Current Stock Quantity 0

MonthYearNumMonthYearInc_Shipment_QtySalesForecast_Qty
Nov-2224274 22
Dec-22242753722
Jan-23242764022
Feb-23242772822
Mar-2324278 22
Apr-2324279 22

 

Product C: Current Stock Quantity 0

MonthYearNumMonthYearInc_Shipment_QtySalesForecast_Qty
Nov-2224274 60
Dec-2224275 60
Jan-2324276 60
Feb-232427718060
Mar-2324278 60
Apr-2324279 60

 

What I want to have is a Measure that calculates the projection of the inventory for those three products according to the following rules:
For Nov-22 it is just the Current Stock Quantity + Inc_Shipment_Qty - SalesForecast_Qty
For the other months it is the value from the previous month + Inc_Shipment_Qty - SalesForecast_Qty

If the value of the measure is less than 0, just show 0

 

With that measure I just want to build a matrix just like this one:

ProductNov-22Dec-22Jan-23Feb-23Mar-23Apr-23
A44834024733720574
B0153339170
C000120600

 

Thank you in advance for any help provided

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @eechever ,

Please try to create measure with below dax formula:

Measure =
VAR cur_product =
    SELECTEDVALUE ( 'Table 2'[Product ] )
VAR cur_monthyear =
    SELECTEDVALUE ( 'Table 2'[MonthYear] )
VAR trans =
    FORMAT ( cur_monthyear, "mmmm yyyy" )
VAR init_quantity_a = 163
VAR init_quantity_b = 0
VAR init_quantity_c = 0
VAR cur_Inc_Shipment_Qty_a =
    CALCULATE (
        MAX ( 'Product A'[Inc_Shipment_Qty] ),
        'Product A'[MonthYear] = cur_monthyear
    )
VAR cur_Inc_Shipment_Qty_b =
    CALCULATE (
        MAX ( 'Product B'[Inc_Shipment_Qty] ),
        'Product B'[MonthYear] = cur_monthyear
    )
VAR cur_Inc_Shipment_Qty_c =
    CALCULATE (
        MAX ( 'Product C'[Inc_Shipment_Qty] ),
        'Product C'[MonthYear] = cur_monthyear
    )
VAR cur_SalesForecast_Qty_a =
    CALCULATE (
        MAX ( 'Product A'[SalesForecast_Qty] ),
        'Product A'[MonthYear] = cur_monthyear
    )
VAR cur_SalesForecast_Qty_b =
    CALCULATE (
        MAX ( 'Product B'[SalesForecast_Qty] ),
        'Product B'[MonthYear] = cur_monthyear
    )
VAR cur_SalesForecast_Qty_c =
    CALCULATE (
        MAX ( 'Product C'[SalesForecast_Qty] ),
        'Product C'[MonthYear] = cur_monthyear
    )
VAR tmp1 =
    FILTER ( ALL ( 'Product A' ), 'Product A'[MonthYear] <= cur_monthyear )
VAR tmp2 =
    FILTER (
        ALL ( 'Product B' ),
        'Product B'[MonthYear] <= cur_monthyear
            && 'Product B'[Inc_Shipment_Qty] <> BLANK ()
    )
VAR tmp3 =
    FILTER (
        ALL ( 'Product C' ),
        'Product C'[MonthYear] <= cur_monthyear
            && 'Product C'[Inc_Shipment_Qty] <> BLANK ()
    )
VAR tmp4 =
    FILTER (
        ALL ( 'Product C' ),
        'Product C'[MonthYear] >= DATE ( 2023, 2, 01 )
            && 'Product C'[MonthYear] <= cur_monthyear
    )
VAR tmp5 =
    FILTER ( ALL ( 'Product B' ), 'Product B'[MonthYear] <= DATE ( 2023, 2, 01 ) )
VAR _value_for_b =
    init_quantity_c + SUMX ( tmp5, [Inc_Shipment_Qty] )
        - SUMX ( tmp5, [SalesForecast_Qty] )
VAR sum_Inc_Shipment_Qty_a =
    SUMX ( tmp1, [Inc_Shipment_Qty] )
VAR sum_SalesForecast_Qty_a =
    SUMX ( tmp1, [SalesForecast_Qty] )
VAR sum_Inc_Shipment_Qty_b =
    SUMX ( tmp2, [Inc_Shipment_Qty] )
VAR sum_SalesForecast_Qty_b =
    SUMX ( tmp2, [SalesForecast_Qty] )
VAR sum_Inc_Shipment_Qty_c =
    SUMX ( tmp3, [Inc_Shipment_Qty] )
VAR sum_SalesForecast_Qty_c =
    SUMX ( tmp3, [SalesForecast_Qty] )
VAR _value =
    SWITCH (
        TRUE (),
        cur_product = "A"
            && trans = "January 2023",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "A"
            && trans = "February 2023",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "A"
            && trans = "March 2023",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "A"
            && trans = "April 2023",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "A"
            && trans = "November 2022",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "A"
            && trans = "December 2022",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "B"
            && trans = "January 2023",
            init_quantity_b + sum_Inc_Shipment_Qty_b - sum_SalesForecast_Qty_b,
        cur_product = "B"
            && trans = "February 2023",
            init_quantity_b + sum_Inc_Shipment_Qty_b - sum_SalesForecast_Qty_b,
        cur_product = "B"
            && trans = "March 2023", _value_for_b,
        cur_product = "B"
            && trans = "April 2023", _value_for_b - cur_SalesForecast_Qty_b,
        cur_product = "B"
            && trans = "November 2022",
            init_quantity_b + sum_Inc_Shipment_Qty_b - sum_SalesForecast_Qty_b,
        cur_product = "B"
            && trans = "December 2022",
            init_quantity_b + sum_Inc_Shipment_Qty_b - sum_SalesForecast_Qty_b,
        cur_product = "C"
            && trans = "January 2023",
            init_quantity_c + sum_Inc_Shipment_Qty_c - sum_SalesForecast_Qty_c,
        cur_product = "C"
            && trans = "February 2023",
            init_quantity_c + SUMX ( tmp4, [Inc_Shipment_Qty] )
                - SUMX ( tmp4, [SalesForecast_Qty] ),
        cur_product = "C"
            && trans = "March 2023",
            init_quantity_c + SUMX ( tmp4, [Inc_Shipment_Qty] )
                - SUMX ( tmp4, [SalesForecast_Qty] ),
        cur_product = "C"
            && trans = "April 2023",
            init_quantity_c + SUMX ( tmp4, [Inc_Shipment_Qty] )
                - SUMX ( tmp4, [SalesForecast_Qty] ),
        cur_product = "C"
            && trans = "November 2022",
            init_quantity_c + sum_Inc_Shipment_Qty_c - sum_SalesForecast_Qty_c,
        cur_product = "C"
            && trans = "December 2022",
            init_quantity_c + sum_Inc_Shipment_Qty_c - sum_SalesForecast_Qty_c
    )
RETURN
    IF ( _value > 0, _value, 0 )

vbinbinyumsft_0-1665476389578.png

 

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
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
eechever
Frequent Visitor

Ok so this solution solve the problem for these particular tables. But how about any table? Either way, thank you very much @Anonymous for your reply

Anonymous
Not applicable

Hi @eechever ,

Please try to create measure with below dax formula:

Measure =
VAR cur_product =
    SELECTEDVALUE ( 'Table 2'[Product ] )
VAR cur_monthyear =
    SELECTEDVALUE ( 'Table 2'[MonthYear] )
VAR trans =
    FORMAT ( cur_monthyear, "mmmm yyyy" )
VAR init_quantity_a = 163
VAR init_quantity_b = 0
VAR init_quantity_c = 0
VAR cur_Inc_Shipment_Qty_a =
    CALCULATE (
        MAX ( 'Product A'[Inc_Shipment_Qty] ),
        'Product A'[MonthYear] = cur_monthyear
    )
VAR cur_Inc_Shipment_Qty_b =
    CALCULATE (
        MAX ( 'Product B'[Inc_Shipment_Qty] ),
        'Product B'[MonthYear] = cur_monthyear
    )
VAR cur_Inc_Shipment_Qty_c =
    CALCULATE (
        MAX ( 'Product C'[Inc_Shipment_Qty] ),
        'Product C'[MonthYear] = cur_monthyear
    )
VAR cur_SalesForecast_Qty_a =
    CALCULATE (
        MAX ( 'Product A'[SalesForecast_Qty] ),
        'Product A'[MonthYear] = cur_monthyear
    )
VAR cur_SalesForecast_Qty_b =
    CALCULATE (
        MAX ( 'Product B'[SalesForecast_Qty] ),
        'Product B'[MonthYear] = cur_monthyear
    )
VAR cur_SalesForecast_Qty_c =
    CALCULATE (
        MAX ( 'Product C'[SalesForecast_Qty] ),
        'Product C'[MonthYear] = cur_monthyear
    )
VAR tmp1 =
    FILTER ( ALL ( 'Product A' ), 'Product A'[MonthYear] <= cur_monthyear )
VAR tmp2 =
    FILTER (
        ALL ( 'Product B' ),
        'Product B'[MonthYear] <= cur_monthyear
            && 'Product B'[Inc_Shipment_Qty] <> BLANK ()
    )
VAR tmp3 =
    FILTER (
        ALL ( 'Product C' ),
        'Product C'[MonthYear] <= cur_monthyear
            && 'Product C'[Inc_Shipment_Qty] <> BLANK ()
    )
VAR tmp4 =
    FILTER (
        ALL ( 'Product C' ),
        'Product C'[MonthYear] >= DATE ( 2023, 2, 01 )
            && 'Product C'[MonthYear] <= cur_monthyear
    )
VAR tmp5 =
    FILTER ( ALL ( 'Product B' ), 'Product B'[MonthYear] <= DATE ( 2023, 2, 01 ) )
VAR _value_for_b =
    init_quantity_c + SUMX ( tmp5, [Inc_Shipment_Qty] )
        - SUMX ( tmp5, [SalesForecast_Qty] )
VAR sum_Inc_Shipment_Qty_a =
    SUMX ( tmp1, [Inc_Shipment_Qty] )
VAR sum_SalesForecast_Qty_a =
    SUMX ( tmp1, [SalesForecast_Qty] )
VAR sum_Inc_Shipment_Qty_b =
    SUMX ( tmp2, [Inc_Shipment_Qty] )
VAR sum_SalesForecast_Qty_b =
    SUMX ( tmp2, [SalesForecast_Qty] )
VAR sum_Inc_Shipment_Qty_c =
    SUMX ( tmp3, [Inc_Shipment_Qty] )
VAR sum_SalesForecast_Qty_c =
    SUMX ( tmp3, [SalesForecast_Qty] )
VAR _value =
    SWITCH (
        TRUE (),
        cur_product = "A"
            && trans = "January 2023",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "A"
            && trans = "February 2023",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "A"
            && trans = "March 2023",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "A"
            && trans = "April 2023",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "A"
            && trans = "November 2022",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "A"
            && trans = "December 2022",
            init_quantity_a + sum_Inc_Shipment_Qty_a - sum_SalesForecast_Qty_a,
        cur_product = "B"
            && trans = "January 2023",
            init_quantity_b + sum_Inc_Shipment_Qty_b - sum_SalesForecast_Qty_b,
        cur_product = "B"
            && trans = "February 2023",
            init_quantity_b + sum_Inc_Shipment_Qty_b - sum_SalesForecast_Qty_b,
        cur_product = "B"
            && trans = "March 2023", _value_for_b,
        cur_product = "B"
            && trans = "April 2023", _value_for_b - cur_SalesForecast_Qty_b,
        cur_product = "B"
            && trans = "November 2022",
            init_quantity_b + sum_Inc_Shipment_Qty_b - sum_SalesForecast_Qty_b,
        cur_product = "B"
            && trans = "December 2022",
            init_quantity_b + sum_Inc_Shipment_Qty_b - sum_SalesForecast_Qty_b,
        cur_product = "C"
            && trans = "January 2023",
            init_quantity_c + sum_Inc_Shipment_Qty_c - sum_SalesForecast_Qty_c,
        cur_product = "C"
            && trans = "February 2023",
            init_quantity_c + SUMX ( tmp4, [Inc_Shipment_Qty] )
                - SUMX ( tmp4, [SalesForecast_Qty] ),
        cur_product = "C"
            && trans = "March 2023",
            init_quantity_c + SUMX ( tmp4, [Inc_Shipment_Qty] )
                - SUMX ( tmp4, [SalesForecast_Qty] ),
        cur_product = "C"
            && trans = "April 2023",
            init_quantity_c + SUMX ( tmp4, [Inc_Shipment_Qty] )
                - SUMX ( tmp4, [SalesForecast_Qty] ),
        cur_product = "C"
            && trans = "November 2022",
            init_quantity_c + sum_Inc_Shipment_Qty_c - sum_SalesForecast_Qty_c,
        cur_product = "C"
            && trans = "December 2022",
            init_quantity_c + sum_Inc_Shipment_Qty_c - sum_SalesForecast_Qty_c
    )
RETURN
    IF ( _value > 0, _value, 0 )

vbinbinyumsft_0-1665476389578.png

 

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.