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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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