Forum Discussion

ipisors's avatar
ipisors
New Member
1 year ago
Solved

How to reference a zero length string

In a DAX formula in power BI, how do I refer to a zero length string (empty string) ?     Is it two double quotes like "" or two single quotes like ''  ?   Also, how do I refer to a Null value (c...
  • speedramps's avatar
    1 year ago

    Please download this PBIX onfrom Onedrive

    Click here 

     

    The input data contains a record with each type of value:-

    • null
    • empty
    • 1 space
    • 2 spaces
    • 3 spaces
    • and text

     

     

    The first interesting thing is that Power BI automatically trims any trailing spaces in text data types.

    Learn here https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-data-types

     

    This means that the 1 space, 2 space and 3 space values will be all be converted to empty !

     

    The next interest thing is that null and empty are treated differently


    ISBLANK(measure) will just detect null
    see https://learn.microsoft.com/en-us/dax/isblank-function-dax

    Whereas IF(measure = BLANK()  treates null and empty as the same !

     

    Answer1 = 
    VAR myvalue = MIN(Yourdata[Value])
    RETURN
    SWITCH(TRUE(),
    ISBLANK(myvalue), 1,
    myvalue = "", 2,
    myvalue = " ",3,
    4
    )

     

    Answer2 = 
    VAR myvalue = MIN(Yourdata[Value])
    RETURN
    SWITCH(TRUE(),
    myvalue = BLANK(), 1,
    myvalue = "", 2,
    myvalue = " ",3,
    4
    )

     

    If you are ever in doubt then edit and play with the example I provided

    Please clcik thumbs up and accept solution buttton