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

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

Reply
Anonymous
Not applicable

Help with cumulative total, sum if, else ...

Hello -

 

I have some snapshots of inventory on a monthly basis. I also have some MRP data, which is forward looking. I have merged the data in sql/power bi and am now trying to do the running total/cumulative sum through power bi.

 

Given the nature of how the data is setup through the merge, prior to today is snapshots (where a snapshot is the inventory at that time), while today or beyond is either a plus or minus. 

 

I would like to setup a measure to take the qty as is from the snapshots if its date is < today, and start a running total if the date is today or beyond. Below, what I have so far, will pass a null if <today, and it needs a slight tweak to display the qty from the snapshot. Table = 'Data'[Qty]. I also have a measure just called [Qty], and that would work as well.

 

Cumulative Qty =
CALCULATE([Qty],
FILTER(ALLSELECTED('CALENDAR'),
'CALENDAR'[Date] >= TODAY() &&
'CALENDAR'[Date] <= MAX('CALENDAR'[Date])))
 
Thanks Nick
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please try this:

Cumulative Qty =
VAR _value =
    CALCULATE (
        [Qty],
        FILTER (
            ALLSELECTED ( 'CALENDAR' ),
            'CALENDAR'[Date] >= TODAY ()
                && 'CALENDAR'[Date] <= MAX ( 'CALENDAR'[Date] )
        )
    )
RETURN
    IF ( _value = null, [Qty], _value )

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,
Eyelyn Qin

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @Anonymous ,

 

Please try this:

Cumulative Qty =
VAR _value =
    CALCULATE (
        [Qty],
        FILTER (
            ALLSELECTED ( 'CALENDAR' ),
            'CALENDAR'[Date] >= TODAY ()
                && 'CALENDAR'[Date] <= MAX ( 'CALENDAR'[Date] )
        )
    )
RETURN
    IF ( _value = null, [Qty], _value )

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,
Eyelyn Qin

Anonymous
Not applicable

Hello @Anonymous - thank you. I marked it as solution and only had to make a minor tweak, replacing null with blank().

 

N

Anonymous
Not applicable

Hi @Anonymous 

Oh... yes, you are right! Sorry for my carelessness.

 

amitchandak
Super User
Super User

@Anonymous ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Try like

CALCULATE([Qty],
FILTER(ALLSELECTED('CALENDAR'),
'CALENDAR'[Date] >= TODAY()-1 &&
'CALENDAR'[Date] <= MAX('CALENDAR'[Date])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak Thanks for your attention. Here is a quick screenshot. The formula is up top. Results on the bottom. The numbers next to the green, are perfect. where is it is yellow, i want those rows to read 51, 55, 37 instead of NULL, under the cumulative qty column.

 

N

 

Nicho248_0-1607927517123.png

 

Helpful resources

Announcements
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 Kudoed Authors