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
Rafgva
Frequent Visitor

Retrieving the last non-zero value from the column (with filters)

Good day everyone!

 

Here is a problem:

We have very simple table with reported values. No dates, only quarter number and a year, as a separate columns.

 

If test was not done, column SCORE contains value ZERO (0).

 

I need to present last non-zero value when quarter slicer is used. That means, if Q2 is selected, I would like to have a measure that returns values for Q2, but in case this value is 0 it will look backward and return non-zero value from Q1.

 

In case Q1 value is zero, it should return 0.

Similarily, if Q1 is non-zero, but Q2 and Q3 are zeroed, selecting Q3 should return value from latest non-zero quarter, hence Q1.

 

PowerBI report and screenshot from Power BI are available here:

https://1drv.ms/u/s!As7K3fOaTOoxg6BiXBulVsHyQ6sSWQ?e=tv51Og

 

For this particular dataset, I wish, after selecting Q2, to see Q1 score for T5 and Q2 scores for T1, T2 and T3 - not null or zero, as I can achieve today.

Similarly for T2, selecting Q3 should retun 60, selecting Q4 should also return 60, not 0 (neither 70 which is MAX).

 

I hope this is described with sufficent clarity. Be safe and thank you in advance for your ideas and hints.

 

Ah, almost forgotten, I am looking for measure. If there is a need to modify source data column, that would be OK, but final calculation must be dynamic. Thanks in advance!

 

RAF

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please use this measure expression.  Note that I changed your Card[Quarter] data type to Whole Number.  It also works as text but it should be changed since numeric comparisons are being made.

 

Last NonZero =
VAR _selquarter =
    MAX ( Card[Quarter] )
VAR _summary =
    CALCULATETABLE (
        SUMMARIZE (
            Card,
            Card[Name],
            Card[Quarter],
            Card[Score]
        ),
        ALL ( Card[Quarter] ),
        Card[Quarter] <= _selquarter
    )
VAR _top1nonzero =
    TOPN (
        1,
        FILTER (
            _summary,
            Card[Score] > 0
        ),
        Card[Quarter], DESC
    )
RETURN
    SUMX (
        _top1nonzero,
        Card[Score]
    )

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Please use this measure expression.  Note that I changed your Card[Quarter] data type to Whole Number.  It also works as text but it should be changed since numeric comparisons are being made.

 

Last NonZero =
VAR _selquarter =
    MAX ( Card[Quarter] )
VAR _summary =
    CALCULATETABLE (
        SUMMARIZE (
            Card,
            Card[Name],
            Card[Quarter],
            Card[Score]
        ),
        ALL ( Card[Quarter] ),
        Card[Quarter] <= _selquarter
    )
VAR _top1nonzero =
    TOPN (
        1,
        FILTER (
            _summary,
            Card[Score] > 0
        ),
        Card[Quarter], DESC
    )
RETURN
    SUMX (
        _top1nonzero,
        Card[Score]
    )

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you for solution and inspiration.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors