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

Running difference by group

I want to calculate revised production order qty per product per day subtracting the available on hand quantity from first orders.

 

Here is the original order quantity table:

Table 1Table 1

And here are currently available quantities:

 

Table 2Table 2

From this, we can see that the first orders don't have to be produced since we can ship the products that we have on hand:

 

New Measure DemonstrationNew Measure Demonstration

How to create this 'Revised Order Qty' measure?

The production order qty needs to be decreased as long as there is something on hand.

(in chronological order)

1 ACCEPTED SOLUTION
AlB
Super User
Super User

Hi @Krzysztof_Hyla 

Please always show your sample data in text-tabular format in addition to (or instead of) the screen captures. A screen cap doesn't allow people to readily copy the data and run a quick test and thus decreases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).

I think you want a calculated column in your Table1 rather than a measure.  If so:

 

Revised Order Qty =
VAR Cum_ =
    CALCULATE (
        SUM ( Table1[Order Qty] ),
        ALLEXCEPT ( Table1, Table1[Product] ),
        Table1[Date] <= EARLIER ( Table1[Date] )
    )
VAR OnHand_ =
    LOOKUPVALUE ( Table2[On Hand Qty], Table2[Product], Table1[Product] )
RETURN
    MAX ( Cum_ - OnHand_, 0 )

Please mark the question solved when done and consider giving kudos if posts are helpful.

 

Cheers  Datanaut

 

View solution in original post

2 REPLIES 2
AlB
Super User
Super User

Hi @Krzysztof_Hyla 

Please always show your sample data in text-tabular format in addition to (or instead of) the screen captures. A screen cap doesn't allow people to readily copy the data and run a quick test and thus decreases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).

I think you want a calculated column in your Table1 rather than a measure.  If so:

 

Revised Order Qty =
VAR Cum_ =
    CALCULATE (
        SUM ( Table1[Order Qty] ),
        ALLEXCEPT ( Table1, Table1[Product] ),
        Table1[Date] <= EARLIER ( Table1[Date] )
    )
VAR OnHand_ =
    LOOKUPVALUE ( Table2[On Hand Qty], Table2[Product], Table1[Product] )
RETURN
    MAX ( Cum_ - OnHand_, 0 )

Please mark the question solved when done and consider giving kudos if posts are helpful.

 

Cheers  Datanaut

 

This is exactly what I needed - thank you !

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.