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
akhaliq7
Post Prodigy
Post Prodigy

In a matrix visual need to show 0 instead of blank from a measure and preserve filters

I would like to display the following:

 

Registered Products =

CALCULATE(

    SUM('Fact Orders'[Registered YN]),

    'Fact Orders'[Category ID] IN {10, 11, 12},

    'Date'[Year] = YEAR(TODAY())

)

 

inside a matrix visual, but for some categories it is displaying blank values this is because I am showing more than 1 measure in values of the matrix visual.

 

What I tried

Using if statement, adding 0 to sum but when I do this more than 1 category shows

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  ,

I have created a simple sample, please refer to.

Create a table includes Year Fields. 

Table 2 = VALUES('Table'[Year])

Then create a measure.

Measure =
VAR _a =
    CALCULATE (
        MAX ( 'Table'[Sales] ),
        FILTER (
            'Table',
            [Portfolio] = "A"
                && [Year] = SELECTEDVALUE ( 'Table 2'[Year] )
        )
    )
VAR _b =
    CALCULATE (
        MAX ( 'Table'[Sales] ),
        FILTER (
            'Table',
            [Portfolio] = "B"
                && [Year] = SELECTEDVALUE ( 'Table 2'[Year] )
        )
    )
VAR result =
    CALCULATE (
        MAX ( 'Table'[Sales] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Portfolio]
                IN VALUES ( 'Table'[Portfolio] )
                    && 'Table'[Year] IN VALUES ( 'Table 2'[Year] )
        )
    )
VAR _answer_ =
    IF ( result <> BLANK (), result, 0 )
RETURN
    IF ( ISINSCOPE ( 'Table'[Portfolio] ), _answer_, _b - _a )

 

vrongtiepmsft_1-1700795120849.png

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

8 REPLIES 8
Anonymous
Not applicable

Hi  ,

I have created a simple sample, please refer to.

Create a table includes Year Fields. 

Table 2 = VALUES('Table'[Year])

Then create a measure.

Measure =
VAR _a =
    CALCULATE (
        MAX ( 'Table'[Sales] ),
        FILTER (
            'Table',
            [Portfolio] = "A"
                && [Year] = SELECTEDVALUE ( 'Table 2'[Year] )
        )
    )
VAR _b =
    CALCULATE (
        MAX ( 'Table'[Sales] ),
        FILTER (
            'Table',
            [Portfolio] = "B"
                && [Year] = SELECTEDVALUE ( 'Table 2'[Year] )
        )
    )
VAR result =
    CALCULATE (
        MAX ( 'Table'[Sales] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Portfolio]
                IN VALUES ( 'Table'[Portfolio] )
                    && 'Table'[Year] IN VALUES ( 'Table 2'[Year] )
        )
    )
VAR _answer_ =
    IF ( result <> BLANK (), result, 0 )
RETURN
    IF ( ISINSCOPE ( 'Table'[Portfolio] ), _answer_, _b - _a )

 

vrongtiepmsft_1-1700795120849.png

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

 

 

 

I need to try this out but do not have the time right now but have accepted the solution thanks.

akhaliq7
Post Prodigy
Post Prodigy

If I am not mistaken this issue may relate to the evaluation context and it is possibly applying the filter first then giving 0 value to all the other categories and adding them in the matrix visual, but not sure how to fix this

Rupak_bi
Super User
Super User

then try to put If statement before calculate. else share sample data.



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

I have tried to create a sample dataset but keep getting different errors when displaying the data, and cannot share the original file as well, I may leave the blanks as it is unless someone else can solve this issue,

I tried putting the if statement before calculate but that didn't work i'll share a sample file after this reply

VAR Result = Calculate code
RETURN IF( ISBLANK(Result), 0, Result)

 

But this ignored the filter applied in calculate

Rupak_bi
Super User
Super User

try this,

 

Registered Products =

CALCULATE(

    if(SUM('Fact Orders'[Registered YN]>0,SUM('Fact Orders'[Registered YN]),0),

    'Fact Orders'[Category ID] IN {10, 11, 12},

    'Date'[Year] = YEAR(TODAY())

)



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/

The above ignores the category id filter which I need to preserve

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.