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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Riggan2023
Frequent Visitor

IF zero use last nonzero?

Hi. I need help. I have a date table and a TOTAL measure

Totals = COALESCE( COUNT('Dataset'[ArchDate]), 0)

that counts total occurances for each date. But if there is no occurances so of course it put 0. But I dont need zeroes, I need to replace them by the last non zero values in the same column just like this. I use filters so the only way to keep it dinamical is to use measure

 

Screenshot_12.png

Thi is my sample pbix

https://file.io/fXnVvkxSIpdd 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Riggan2023 ,

I updated your sample pbix file(see the attachment), please check if that is what you want.

1. Create a measure as below to get the count of per ArchDate

Measure = COUNT('Dataset'[ArchDate])

2. Update the formula of measure [Totals] as below

Totals =
VAR _seldate =
    SELECTEDVALUE ( 'MyCalendar'[Date] )
VAR _predate =
    CALCULATE (
        MAX ( 'Dataset'[ArchDate] ),
        FILTER (
            ALLSELECTED ( 'Dataset' ),
            'Dataset'[ArchDate] < _seldate
                && NOT ( ISBLANK ( [Measure] ) )
        )
    )
VAR _count =
    CALCULATE (
        [Measure],
        FILTER ( ALLSELECTED ( 'Dataset' ), 'Dataset'[ArchDate] = _predate )
    )
RETURN
    IF ( NOT ( ISBLANK ( [Measure] ) ), [Measure], _count )

yingyinr_0-1674095504361.png

Best Regards

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Riggan2023 ,

I updated your sample pbix file(see the attachment), please check if that is what you want.

1. Create a measure as below to get the count of per ArchDate

Measure = COUNT('Dataset'[ArchDate])

2. Update the formula of measure [Totals] as below

Totals =
VAR _seldate =
    SELECTEDVALUE ( 'MyCalendar'[Date] )
VAR _predate =
    CALCULATE (
        MAX ( 'Dataset'[ArchDate] ),
        FILTER (
            ALLSELECTED ( 'Dataset' ),
            'Dataset'[ArchDate] < _seldate
                && NOT ( ISBLANK ( [Measure] ) )
        )
    )
VAR _count =
    CALCULATE (
        [Measure],
        FILTER ( ALLSELECTED ( 'Dataset' ), 'Dataset'[ArchDate] = _predate )
    )
RETURN
    IF ( NOT ( ISBLANK ( [Measure] ) ), [Measure], _count )

yingyinr_0-1674095504361.png

Best Regards

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.