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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Calculated Column for Sum while comparing to another value

I'm looking to create a calculated column to sum a value (Quantity) from another table. Until the calculated amount (Quantity) is >= another value (total on hand). I'm not 100% certain what direction to head towards. I have attempted a couple of things but all directions just get me the grand total amounts of the matching records, shown at the bottom of the screen shot. Hopefully I explained what I am attempting to accomplish well enough. Any suggestions are greatly appreciated!

 

zachhenry_0-1650573947080.png

 

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

Please try calculated columns as below:

Quantity running total = 
CALCULATE (
    SUM ( 'Table'[Quantity] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Transaction Date] >= EARLIER ( 'Table'[Transaction Date] )
    )
)
Extend Purchase price running total = 
CALCULATE (
    SUM ( 'Table'[Extend Purchase Price] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Transaction Date] >= EARLIER ( 'Table'[Transaction Date] )
    )
)

 

7.png

Result1 = 
CALCULATE (
    MIN ( 'Table'[Quantity running total] ),
    FILTER (
        'Table',
        'Table'[Quantity running total] >= 'Table 2'[Total of Hand]
            && 'Table'[Item ID] = 'Table 2'[Item ID]
    )
)
Result2 = 
CALCULATE (
    MAX ( 'Table'[Extend Purchase price running total] ),
    FILTER (
        'Table',
        'Table'[Quantity running total] = 'Table 2'[Result1]
            && 'Table'[Item ID] = 'Table 2'[Item ID]
    )
)

result:

8.png

Best Regards,
Community Support Team _ Eason

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

I'm following what you are doing. So Close! Question though. What do I do in the instance that I have more then one record for a given item id on a given day? That seems to be messing with the running total. I very much appreciate your effort to assist! 

 

zachhenry_0-1650923253680.png

zachhenry_1-1650923329413.png

zachhenry_2-1650923344014.png

 

Thanks!

 

Zach

 

Hi, @Anonymous 

You can try to add an Index column after sorting the data in 'Transform data' (in descending order of ItemID and Transaction).

Then recalculate the running total based on this new Index column rather than 'Transaction Date'.

 

Best Regards,
Community Support Team _ Eason

v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

Please try calculated columns as below:

Quantity running total = 
CALCULATE (
    SUM ( 'Table'[Quantity] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Transaction Date] >= EARLIER ( 'Table'[Transaction Date] )
    )
)
Extend Purchase price running total = 
CALCULATE (
    SUM ( 'Table'[Extend Purchase Price] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Transaction Date] >= EARLIER ( 'Table'[Transaction Date] )
    )
)

 

7.png

Result1 = 
CALCULATE (
    MIN ( 'Table'[Quantity running total] ),
    FILTER (
        'Table',
        'Table'[Quantity running total] >= 'Table 2'[Total of Hand]
            && 'Table'[Item ID] = 'Table 2'[Item ID]
    )
)
Result2 = 
CALCULATE (
    MAX ( 'Table'[Extend Purchase price running total] ),
    FILTER (
        'Table',
        'Table'[Quantity running total] = 'Table 2'[Result1]
            && 'Table'[Item ID] = 'Table 2'[Item ID]
    )
)

result:

8.png

Best Regards,
Community Support Team _ Eason

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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