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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

How to get summary of consecutive non zero values in a measure?

I have a scenario where I need to get summary of values till it encounters zero and reset the summary to zero once it has the zero value.

 

DKS1_0-1724414451673.png

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi  @Anonymous ,

 

Here are the steps you can follow:

1.Create calculated column.

Column1 =
IF(
   'Table'[YELLOW]=0,1,0)
Column2 =
SUMX(
    FILTER(ALL('Table'),
    'Table'[FW_ID]<=EARLIER('Table'[FW_ID])),[Column1])

vyangliumsft_0-1724636799621.png

2. Create measure.

Test1 =
IF(
    MAX('Table'[Column1])=1,BLANK(),
COUNTX(
    FILTER(ALLSELECTED('Table'),
    'Table'[Column2]=MAX('Table'[Column2])&&[Column1]<>1),[FW_ID]))
Test2 =
SUMX(
    FILTER(ALL('Table'),[Test1]>1),[YELLOW])

3. Result:

vyangliumsft_1-1724636799622.png

 

 

Best Regards,

Liu Yang

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

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for cumulative sum grouped by non-consecutive-zero.

 

Jihwan_Kim_0-1724644254258.png

 

 

 

expected result measure: = 
VAR _yellow =
    ADDCOLUMNS ( ALL ( data ), "@yellow", [yellow:] )
VAR _condition =
    ADDCOLUMNS ( _yellow, "@condition", IF ( [@yellow] = 0, 1, 0 ) )
VAR _group =
    ADDCOLUMNS (
        _condition,
        "@group",
            SUMX (
                FILTER ( _condition, data[fw_id] <= EARLIER ( data[fw_id] ) ),
                [@condition]
            )
    )
VAR _currentrowgroup =
    MAXX ( FILTER ( _group, data[fw_id] = MAX ( data[fw_id] ) ), [@group] )
RETURN
    SUMX (
        FILTER (
            _group,
            [@group] = _currentrowgroup
                && data[fw_id] <= MAX ( data[fw_id] )
        ),
        [@yellow]
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for cumulative sum grouped by non-consecutive-zero.

 

Jihwan_Kim_0-1724644254258.png

 

 

 

expected result measure: = 
VAR _yellow =
    ADDCOLUMNS ( ALL ( data ), "@yellow", [yellow:] )
VAR _condition =
    ADDCOLUMNS ( _yellow, "@condition", IF ( [@yellow] = 0, 1, 0 ) )
VAR _group =
    ADDCOLUMNS (
        _condition,
        "@group",
            SUMX (
                FILTER ( _condition, data[fw_id] <= EARLIER ( data[fw_id] ) ),
                [@condition]
            )
    )
VAR _currentrowgroup =
    MAXX ( FILTER ( _group, data[fw_id] = MAX ( data[fw_id] ) ), [@group] )
RETURN
    SUMX (
        FILTER (
            _group,
            [@group] = _currentrowgroup
                && data[fw_id] <= MAX ( data[fw_id] )
        ),
        [@yellow]
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Hi  @Anonymous ,

 

Here are the steps you can follow:

1.Create calculated column.

Column1 =
IF(
   'Table'[YELLOW]=0,1,0)
Column2 =
SUMX(
    FILTER(ALL('Table'),
    'Table'[FW_ID]<=EARLIER('Table'[FW_ID])),[Column1])

vyangliumsft_0-1724636799621.png

2. Create measure.

Test1 =
IF(
    MAX('Table'[Column1])=1,BLANK(),
COUNTX(
    FILTER(ALLSELECTED('Table'),
    'Table'[Column2]=MAX('Table'[Column2])&&[Column1]<>1),[FW_ID]))
Test2 =
SUMX(
    FILTER(ALL('Table'),[Test1]>1),[YELLOW])

3. Result:

vyangliumsft_1-1724636799622.png

 

 

Best Regards,

Liu Yang

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

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.