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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Tontaube2
Helper IV
Helper IV

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
Tontaube2
Helper IV
Helper IV

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors