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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
MadsEmil
Frequent Visitor

In matrix, omit blank rows, but assign zeros to blanks when some values in row are non-blank

The data:

I have a dataset, that I would like to visualise in a matrix using a three-level row hierarchy and a date hierarchy in the columns. Some combinations of Group/Subgroup/Type and Year have missing values (see image below).

 

Currentmatrix.jpg

Desired output:

I would like to have zeros instead of blanks in the full matrix, as shown in the image below.

 

Desiredoutput1.jpg

However, if a row has only blank values, I want it omitted from the matrix, as shown in the image below.

 

Desiredouput2.jpg

Summary:

How do I replace blank values with zeros when there are non-blank values in the row in the current context, but omit the row when there are only blank values in the current context. I have attached the sample data I've used in the above examples in the table below.

 

Thank you for your help 🙂

 

GroupSubgroupTypeYearAmount
Group1Subgroup1Type12020200
Group1Subgroup1Type22020110
Group1Subgroup2Type32020100
Group1Subgroup2Type4202050
Group2Subgroup1Type1202040
Group2Subgroup1Type2202020
Group2Subgroup2Type3202019
Group2Subgroup2Type4202010
Group3Subgroup1Type22020-2
Group3Subgroup2Type420203
Group4Subgroup1Type12020-192
Group4Subgroup1Type22020-104
Group4Subgroup2Type32020-95
Group4Subgroup2Type42020-48
Group5Subgroup1Type12020-32
Group5Subgroup1Type22020-14
Group5Subgroup2Type32020-15
Group5Subgroup2Type42020-10
Group1Subgroup1Type12021209
Group1Subgroup1Type2202192
Group1Subgroup2Type3202187
Group1Subgroup2Type4202160
Group2Subgroup1Type2202122
Group2Subgroup2Type3202121
Group2Subgroup2Type4202112
Group3Subgroup1Type120211
Group3Subgroup1Type22021-2
Group3Subgroup2Type32021-1
Group3Subgroup2Type420214
Group4Subgroup1Type12021-167
Group4Subgroup1Type22021-91
Group4Subgroup2Type32021-86
Group4Subgroup2Type42021-57
Group5Subgroup1Type22021-16
Group5Subgroup2Type32021-16
Group5Subgroup2Type42021-12

 

1 ACCEPTED SOLUTION

Hi @MadsEmil,

I'm attaching a pbix file with my solution.
I hope this could solve your issue.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




View solution in original post

9 REPLIES 9
_AAndrade
Super User
Super User

For the firts matrix with all year use my second measure it the IF statement.
And for the matrix of each year use your current measure, becaus PBI by default hide the blank values.

 





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Oh, I apologize, I have not been completely clear in formulating my question then. There should only be one matrix, which the user should be able to filter, among other things filter on Year. So the measure needs to be able to handle both behaviors.

Hum ok. So I didn't understand your question. How can PBI know when use zero or blank? What should be the criteria to hide the row or show zero?

 





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Whether there are any non-blank values in the row. So if both years are shown, the blanks should be shown as zeros, as there are some values in the row that are not blank. When all values in a row are blank however, the row should not be shown. However, if I do a simple if blank then 0 measure, the rows always show up.

Hi @MadsEmil,

I'm attaching a pbix file with my solution.
I hope this could solve your issue.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Excellent! Thank you very much 🙂

Here's an example of how this might be achieved:

Sum of amount = SUM(Table1[Amount])
Sum w 0 = 
    VAR _Group = MAX(Table1[Group])
    VAR _Subgroup = MAX(Table1[Subgroup])
    VAR _Type = MAX(Table1[Type])
    VAR _Count = 
        COUNTX(
            FILTER(
                ALLSELECTED(Table1),
                Table1[Group] = _Group
                && Table1[Subgroup] = _Subgroup
                && Table1[Type] = _Type
            ),

            [Sum of amount]
        )

RETURN
    IF(
        _Count = 0,
        BLANK(),
        IF(
            ISBLANK([Sum of amount]), 
            0, 
            [Sum of amount])
    )

 However, while this does hide rows with only blank values, it does not show zeros instead of blanks when rows are shown. I hope this cleared up any confusion about my question.

_AAndrade
Super User
Super User

Hi @MadsEmil,

If think the easist thing to do is using two diferent measures.
The actual measure is hidding the row if the results is blank.
So you need another measure like this:
IF( ISBLANK([Your measure]), 0, [Your measure])





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Thank you for replying so fast! I'm unsure exactly what you mean. Which measure would I put into the values field of my matrix then?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors