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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
dantheram
Helper II
Helper II

Running sum and 0 (zero) values

hi all

 

could you help me fix this forumla?

 

CALCULATE (
    SUM ('Incident Facts'[PfPI Minutes]),
    FILTER (ALLSELECTED('Calendar'[Date],'Calendar'[Period],'Calendar'[Financial Year]),'Calendar'[Date] <= MAX ('Incident Facts'[Incident Create Date] )))
 
what happens is when a date has a 0 value the report returns a blank, rather than using the value for the preceeding date. 
 
e.g. 
A - 1
B - 2
C - 0
D - 4
 
should be -
A - 1
B - 3
C - 3
D - 7
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @dantheram ,

For the example you mentioned I think it can be solved using the overlay method. I create a table as you mentioned.

vyilongmsft_0-1709869650371.png

Then I create a new measure to write the DAX code.

Measure =
VAR _currentKey =
    SELECTEDVALUE ( 'Table'[Key] )
VAR _previousKey =
    CALCULATE (
        MAX ( 'Table'[Key] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Key] <= _currentKey )
    )
RETURN
    SUMX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Key] <= _previousKey ),
        'Table'[Value]
    )

Finally we will get what we want.

vyilongmsft_1-1709870499836.png

 

 

 

Best Regards

Yilong Zhou

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

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @dantheram ,

For the example you mentioned I think it can be solved using the overlay method. I create a table as you mentioned.

vyilongmsft_0-1709869650371.png

Then I create a new measure to write the DAX code.

Measure =
VAR _currentKey =
    SELECTEDVALUE ( 'Table'[Key] )
VAR _previousKey =
    CALCULATE (
        MAX ( 'Table'[Key] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Key] <= _currentKey )
    )
RETURN
    SUMX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Key] <= _previousKey ),
        'Table'[Value]
    )

Finally we will get what we want.

vyilongmsft_1-1709870499836.png

 

 

 

Best Regards

Yilong Zhou

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

DemoFour
Responsive Resident
Responsive Resident

Hay @dantheram 

Do you have some dummy data to look at for your desired result? 

i'll create some dummy data - i have half fixed it but it caused another graph to miscalculate now 😞

nearly fix it with this but it doesnt show "0" at the very start. so if week 1 is blank it leaves it blank rather than "0". as soon as a values occurs for a week it works perfectly 

 

Run2 = Var _lastDate =
    CALCULATE(max('Incident Facts'[Incident Create Date]),REMOVEFILTERS())
    RETURN
    CALCULATE(
        SUM('Incident Facts'[PfPI Minutes]),
        USERELATIONSHIP ( 'Calendar'[Date], 'Incident Facts'[Incident Create Date] ),
        FILTER(
            ALLSELECTED('Calendar'),
            'Calendar'[Date] <= MAX ('Calendar'[Date])
            && 'Calendar'[Financial Year] = MAX( 'Calendar'[Financial Year])
            && MIN('Calendar'[Date] ) <= _lastDate))

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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