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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Omid_123
New Member

Deducting Qty from different location in sequence

Hi,

I am trying to find a code that would help me with the below logic. Any help is highly appreciated.

 

Inputs:

  • Jobs with quantities .
  • Each job is sequenced based on a date.
  • There are 4 inventory locations and they are prioritized based on consumption.

Logic: Deducation from Location 1, if location1 reaches to 0 qty then deduct from location2 and if location2 reaches to 0 qty then location3....... until location4 and if location4 is empty then "Order" text once it reaches negative.

 

Output:

  • Clear or not clear
  • If "Order" then short by how much in total.

 

Table 1
JobDatePart NumberQty RequiredClear?Short in Total
101-Jul-22ABC4Clear 
202-Jul-22ABC2ORDER-1
303-Jul-22DEF5Clear 
404-Jul-22GHI1Clear 
505-Jul-22DEF3ORDER-2
606-Jul-22ABC4ORDER-5

 

Table 2
Part NumberLocation 1Location 2Location 3 Location 4
ABC3110
DEF5010
GHI0001

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Omid_123 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a calculated columns as below to get the [Short in Total]

PS: If you have more locations, suggest that unpivot these location columns in Power Query Editor first...

yingyinr_2-1656320380120.png

Short in Total = 
VAR _tab2qty =
    CALCULATE (
        SUM ( 'Table 2 (2)'[Value] ),
        FILTER ( 'Table 2 (2)', 'Table 2 (2)'[Part Number] = 'Table 1'[Part Number] )
    )
    // CALCULATE (
    //     SUM ( 'Table 2'[Location 1] ),
    //     FILTER ( 'Table 2', 'Table 1'[Part Number] = 'Table 2'[Part Number] )
    // )
    //     + CALCULATE (
    //         SUM ( 'Table 2'[Location 2] ),
    //         FILTER ( 'Table 2', 'Table 1'[Part Number] = 'Table 2'[Part Number] )
    //     )
    //     + CALCULATE (
    //         SUM ( 'Table 2'[Location 3] ),
    //         FILTER ( 'Table 2', 'Table 1'[Part Number] = 'Table 2'[Part Number] )
    //     )
    //     + CALCULATE (
    //         SUM ( 'Table 2'[Location 4] ),
    //         FILTER ( 'Table 2', 'Table 1'[Part Number] = 'Table 2'[Part Number] )
    //     )
VAR _culqty =
    CALCULATE (
        SUM ( 'Table 1'[Qty Required] ),
        FILTER (
            'Table 1',
            'Table 1'[Part Number] = EARLIER ( 'Table 1'[Part Number] )
                && 'Table 1'[Date] <= EARLIER ( 'Table 1'[Date] )
        )
    )
RETURN
    IF ( _tab2qty - _culqty >= 0, BLANK (), _tab2qty - _culqty )

yingyinr_1-1656320289180.png

2. Create a calculated column as below to get the [Clear?]

Clear? = IF(ISBLANK([Short in Total]),"Clear","ORDER")

If the above one can't help you get the desired result, please provide more sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi  @Omid_123 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a calculated columns as below to get the [Short in Total]

PS: If you have more locations, suggest that unpivot these location columns in Power Query Editor first...

yingyinr_2-1656320380120.png

Short in Total = 
VAR _tab2qty =
    CALCULATE (
        SUM ( 'Table 2 (2)'[Value] ),
        FILTER ( 'Table 2 (2)', 'Table 2 (2)'[Part Number] = 'Table 1'[Part Number] )
    )
    // CALCULATE (
    //     SUM ( 'Table 2'[Location 1] ),
    //     FILTER ( 'Table 2', 'Table 1'[Part Number] = 'Table 2'[Part Number] )
    // )
    //     + CALCULATE (
    //         SUM ( 'Table 2'[Location 2] ),
    //         FILTER ( 'Table 2', 'Table 1'[Part Number] = 'Table 2'[Part Number] )
    //     )
    //     + CALCULATE (
    //         SUM ( 'Table 2'[Location 3] ),
    //         FILTER ( 'Table 2', 'Table 1'[Part Number] = 'Table 2'[Part Number] )
    //     )
    //     + CALCULATE (
    //         SUM ( 'Table 2'[Location 4] ),
    //         FILTER ( 'Table 2', 'Table 1'[Part Number] = 'Table 2'[Part Number] )
    //     )
VAR _culqty =
    CALCULATE (
        SUM ( 'Table 1'[Qty Required] ),
        FILTER (
            'Table 1',
            'Table 1'[Part Number] = EARLIER ( 'Table 1'[Part Number] )
                && 'Table 1'[Date] <= EARLIER ( 'Table 1'[Date] )
        )
    )
RETURN
    IF ( _tab2qty - _culqty >= 0, BLANK (), _tab2qty - _culqty )

yingyinr_1-1656320289180.png

2. Create a calculated column as below to get the [Clear?]

Clear? = IF(ISBLANK([Short in Total]),"Clear","ORDER")

If the above one can't help you get the desired result, please provide more sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors