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
erhang
Helper II
Helper II

dax formula help (Distribution)

Hi dear Power BI Family ;

 

İ am happy to be here to take always support from you  , so thanks in advance to everybody.

 

İ need your helps one more time to create a formula about below situation .

 

İ have two tables as below  .

 

Table 1 : contains product , request delivery date, and requested quantities .

Table 2 : contains the stock quantities of the products.

 

 

 

 

Capture8.JPG

 

 

 

As you see i have different delivery dates with different quantities.İ just want to distrubute the stock quantities based on delivery dates..İ would like to show you to  step by step ( based on only one product ) .İ want to tell like that because the issue has some interesting details so just i want to tell correctly 

 

For Product PRC1 distribution: 

 

 

 

Capture5.JPG

 

 

For Product PRC2 distribution: 

 

 

Capture6.JPG

 

 

and the finally whole new table 1 will be as below : 

Capture7.JPG

 

 

 I hope it is possible to make distrubition like that 

 

İf it is possible could you help me pls about this issue 

 

Thanks 

Erhan 

2 ACCEPTED SOLUTIONS
Zubair_Muhammad
Community Champion
Community Champion

HI @erhang

 

Try this MEASURE

 

Distributed Stocks =
VAR stock_to_distirubute =
    CALCULATE (
        SUM ( Table2[Stock Qty] ),
        CROSSFILTER ( Table2[Product], Table1[Product], BOTH )
    )
VAR Cumulativestock =
    CALCULATE (
        SUM ( Table1[Requested Qty] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Product] ),
            Table1[Rquested Delivery Date]
                <= SELECTEDVALUE ( Table1[Rquested Delivery Date] )
        )
    )
VAR myqty =
    IF (
        Cumulativestock > stock_to_distirubute,
        SELECTEDVALUE ( Table1[Requested Qty] )
            - ( Cumulativestock - stock_to_distirubute ),
        SELECTEDVALUE ( Table1[Requested Qty] )
    )
RETURN
    IF ( myqty < 0, 0, myqty )

Regards
Zubair

Please try my custom visuals

View solution in original post

Hi @erhang

 

To solve this situation, first add a calculated column as follows

 

Adjusted Delivery Date =
Table1[Rquested Delivery Date]
    + Table1[Document Number] / 10000

Now you can revise the original measure by replacing Requested Delivery Date with Adjsuted Delivery Date

i.e.

 

Distributed Stocks =
VAR stock_to_distirubute =
    CALCULATE (
        SUM ( Table2[Stock Qty] ),
        CROSSFILTER ( Table2[Product], Table1[Product], BOTH )
    )
VAR Cumulativestock =
    CALCULATE (
        SUM ( Table1[Requested Qty] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Product] ),
            Table1[Adjusted Delivery Date]
                <= SELECTEDVALUE ( Table1[Adjusted Delivery Date] )
        )
    )
VAR myqty =
    IF (
        Cumulativestock > stock_to_distirubute,
        SELECTEDVALUE ( Table1[Requested Qty] )
            - ( Cumulativestock - stock_to_distirubute ),
        SELECTEDVALUE ( Table1[Requested Qty] )
    )
RETURN
    IF ( myqty < 0, 0, myqty )

Regards
Zubair

Please try my custom visuals

View solution in original post

10 REPLIES 10

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.