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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

IF SelectedValue is Blank, Blank, otherwise check if Number, otherwise output...

How do I write this in proper DAX?

 

So far I´ve tested several methods - but I always get an error or an syntax-error

 

Test =
IF (
     ISBLANK (SELECTEDVALUE( 'FaktKPI'[BewertungKPI] ), BLANK()), IF (ISNUMBER (SELECTEDVALUE ( FaktKPI[BewertungKPI] ), (SELECTEDVALUE ( FaktKPI[BewertungKPI] ),"yes"
)
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

Cleaning up your mismatching parentheses and using a variable, you can write your formula like this:

Test =
VAR _KPI = SELECTEDVALUE ( 'FaktKPI'[BewertungKPI] )
RETURN
    IF (
        ISBLANK ( _KPI ),
        BLANK (),
        IF (
            ISNUMBER ( _KPI ),
            _KPI,
            "yes"
        )
    )

 This can be further simplified as

Test =
VAR _KPI = SELECTEDVALUE ( 'FaktKPI'[BewertungKPI] )
RETURN
    IF ( ISBLANK ( _KPI ) || ISNUMBER ( _KPI ), _KPI, "yes" )

 

However, you're still likely to have a problem since IF cannot output text in some cases and numbers in other cases. It has to output the same data type for both cases. Thus you need to either format your number as text or else use a number instead of "yes". For example, if you want to show your KPI as a percentage with two decimal places, you could use FORMAT to convert the number to text like this:

Test =
VAR _KPI = SELECTEDVALUE ( 'FaktKPI'[BewertungKPI] )
RETURN
    IF (
        ISBLANK ( _KPI ) || ISNUMBER ( _KPI ),
        FORMAT ( _KPI, "0.00%" ),
        "yes"
    )

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thank you very much!

AlexisOlson
Super User
Super User

Cleaning up your mismatching parentheses and using a variable, you can write your formula like this:

Test =
VAR _KPI = SELECTEDVALUE ( 'FaktKPI'[BewertungKPI] )
RETURN
    IF (
        ISBLANK ( _KPI ),
        BLANK (),
        IF (
            ISNUMBER ( _KPI ),
            _KPI,
            "yes"
        )
    )

 This can be further simplified as

Test =
VAR _KPI = SELECTEDVALUE ( 'FaktKPI'[BewertungKPI] )
RETURN
    IF ( ISBLANK ( _KPI ) || ISNUMBER ( _KPI ), _KPI, "yes" )

 

However, you're still likely to have a problem since IF cannot output text in some cases and numbers in other cases. It has to output the same data type for both cases. Thus you need to either format your number as text or else use a number instead of "yes". For example, if you want to show your KPI as a percentage with two decimal places, you could use FORMAT to convert the number to text like this:

Test =
VAR _KPI = SELECTEDVALUE ( 'FaktKPI'[BewertungKPI] )
RETURN
    IF (
        ISBLANK ( _KPI ) || ISNUMBER ( _KPI ),
        FORMAT ( _KPI, "0.00%" ),
        "yes"
    )
tamerj1
Super User
Super User

Test =
IF (
NOT ISBLANK ( SELECTEDVALUE ( 'FaktKPI'[BewertungKPI] ) ),
IF (
ISNUMBER ( SELECTEDVALUE ( 'FaktKPI'[BewertungKPI] ) ),
SELECTEDVALUE ( FaktKPI[BewertungKPI] ),
"yes"
)
)

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.