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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

Replace the blank values of my matrix (driven by an if statement) with 0

Hello,

 

I have a long if statement being used as a count in a matrix figure. I would very much like the blanks to be zeros. Everything I have tried has come up short. Thanks in advance for any assistance.

 Capture.PNG Capture.PNG

 

 

 

8 REPLIES 8
MFelix
Super User
Super User

Hi @Anonymous,

 

First of all you have several issues with your formula that make it more complex to read:

 

Instead of using several IF within IF you should use the SWITCH function check this link, this is basically a IF on steroids and helps you get your DAX measure in a better way.

 

I would also consider instead of making a huge formula like you have make several smaller ones and then combine into a single one.

 

Second of all you should use https://www.daxformatter.com/ to format your DAX measure in a better way to be more readable this helps you formatting your code.

 

For the result try to create a new measure where you do the following:

 

Days in status = IF ( [Days in Status (Base Work)] = Blank() ; 0 ; [Days in Status (Base Work)])

Use this formula on your report to give the expected result.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

@MFelix, thanks for the reply

 

Here is the if statement in the easier to read format.

 

Days in Status (Base Work) =
IF (
    'NOT-WORKED'[- Status Date] <= 0 + CALCULATE (
                AVERAGE ( 'NOT-WORKED'[Base Range] ),
                ALL ( Vlookup[Status] )
            )
        && 'NOT-WORKED'[- Status Date] >= -10 + CALCULATE (
                    AVERAGE ( 'NOT-WORKED'[Base Range] ),
                    ALL ( Vlookup[Rehab Status] )
                ),
    "Upcoming",
    IF (
        'NOT-WORKED'[- Status Date] > 0 + CALCULATE (
                    AVERAGE ( 'NOT-WORKED'[Base Range] ),
                    ALL ( Vlookup[Rehab Status] )
                )
            && 'NOT-WORKED'[- Status Date] <= 15 + CALCULATE (
                        AVERAGE ( 'NOT-WORKED'[Base Range] ),
                        ALL ( Vlookup[Status] )
                    ),
        "0 to 15 days",
        IF (
            'NOT-WORKED'[- Status Date] > 15 + CALCULATE (
                        AVERAGE ( 'NOT-WORKED'[Base Range] ),
                        ALL ( Vlookup[Status] )
                    )
                && 'NOT-WORKED'[- Status Date] <= 30 + CALCULATE (
                            AVERAGE ( 'NOT-WORKED'[Base Range] ),
                            ALL ( Vlookup[Status] )
                        ),
            "16 to 30 days",
            IF (
                'NOT-WORKED'[- Status Date] > 30 + CALCULATE (
                            AVERAGE ( 'NOT-WORKED'[Base Range] ),
                            ALL ( Vlookup[Status] )
                        )
                    && 'NOT-WORKED'[- Status Date] <= 45 + CALCULATE (
                                AVERAGE ( 'NOT-WORKED'[Base Range] ),
                                ALL ( Vlookup[Status] )
                            ),
                "31 to 45 days",
                IF (
                    'NOT-WORKED'[- Status Date] > 45 + CALCULATE (
                                AVERAGE ( 'NOT-WORKED'[Base Range] ),
                                ALL ( Vlookup[Status] )
                            ),
                    "46+ days",
                    "x"
                )
            )
        )
    )
)

 

 

The Switch function isnt applicable because it relies on a constant value and mine are ranges.

 

The formula you supplied doesnt work because there are no blank values in the column itself, the blank values come with the matrix because there are no values that match the column, row combination.

 

Do  you have any other ideas?

Hi @Anonymous,

 

In my experience with SWITCH i have used it for constant values but also for variables and ranges depends on the syntax and how you set it up, but maybe in some models and setups it doesn't work.

 

Can you also share some sample data or a PBIX file?

 

Regards,

MFelix

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

@MFelix

 

I got the SWITCH to work.

 

Days in Status (Base Work) =
VAR Status_Average =
    CALCULATE (
        AVERAGE ( 'NOT-WORKED'[Base Range] ),
        ALL ( Vlookup[Status] )
    )
VAR Rehab_Average =
    CALCULATE (
        AVERAGE ( 'NOT-WORKED'[Base Range] ),
        ALL ( Vlookup[Rehab Status] )
    )
RETURN
    SWITCH (
        TRUE (),
        'NOT-WORKED'[- Status Date] <= 0 + Status_Average
            && 'NOT-WORKED'[- Status Date] >= -10 + Rehab_Average, "Upcoming",
        'NOT-WORKED'[- Status Date] > 0 + Status_Average
            && 'NOT-WORKED'[- Status Date] <= 15 + Rehab_Average, "0 to 15 days",
        'NOT-WORKED'[- Status Date] > 15 + Status_Average
            && 'NOT-WORKED'[- Status Date] <= 30 + Rehab_Average, "16 to 30 days",
        'NOT-WORKED'[- Status Date] > 30 + Status_Average
            && 'NOT-WORKED'[- Status Date] <= 45 + Rehab_Average, "31 to 45 days",
        'NOT-WORKED'[- Status Date] > 45 + Status_Average, "46+ days",
        "x"
    )

 

When I do the column you suggested I get a circular dependency error

 

Capture.PNG

Hi @Anonymous,

 

As @Anonymous mentioned this is getting this value because of using a column try to implement this on a measure and should work,

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

@Anonymous,

Please write measures instead of calculated columns. You can check the difference between measures and calculated columns in the blog below.

http://exceleratorbi.com.au/calculated-columns-vs-measures-dax/

Regards,
Lydia

Anonymous
Not applicable

@Anonymous @MFelix

 

Am I supposed to use measures for switch statements? If so, what aggregate should I be using?

Hi @Anonymous,

 

You can use the Switch function also in calculated columns however as a best practice you should use measure as long as it possible.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.