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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
ipisors
New Member

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 (coming back from sql server datasource), is it just the word Null?  

 

Example, my formula might be something like IF(column is empty,"N/A",column)

1 ACCEPTED SOLUTION
speedramps
Community Champion
Community Champion

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

speedramps_0-1739385996107.png

 

 

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

speedramps_1-1739386018130.png

Please clcik thumbs up and accept solution buttton

 

View solution in original post

8 REPLIES 8
speedramps
Community Champion
Community Champion

@Fowmy @AlexisOlson 

I think we all gave answers abour the same time


Worth adding 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

 

Where as SLQ and EXCEL do not.

This often causes confussion when trying to reconciling totals between SQL, EXCEL and Power BI

👍

speedramps
Community Champion
Community Champion

Thank you @ipisors 

 

Your kind words are much appreciated !

Especially afer just receiving some nasty words from the previous member I tried to help 🙄.

Forums can be a scary place.

Good luck with your null, blank and n/a project. 👍  

Fowmy
Super User
Super User

@ipisors 

IF( OR( ISBLANK( Table[Column] ), Table[Column] = "" ), "N/A", Table[Column] )

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

ipisors
New Member

Thank you very much gentlemen!  Appreciate the helpful context and info.  

speedramps
Community Champion
Community Champion

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

speedramps_0-1739385996107.png

 

 

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

speedramps_1-1739386018130.png

Please clcik thumbs up and accept solution buttton

 

AlexisOlson
Super User
Super User

Zero length string is "". Null is BLANK().

 

You can do checks like

IF ( OR ( ISBLANK( [Col1] ), [Col1] = "" ), "N/A", [Col1] )

IF ( LEN ( [Col1] ) = 0, "N/A", [Col1] )

IF ( [Col1] = BLANK(), "N/A", [Col1] )

 

I don't recommend the last one since "" = BLANK() is true but "" == BLANK() is false.

 

ISBLANK - DAX Guide

=blank() is not working in a Filtered Rows fx

I'm using 

= Table.SelectRows(dbo_tbl_PatientVisit_Allergy, each [Description] = Blank() or [Description] = "Unknown")

 

but it says "the name Blank wasn't recognized

@ipisors 
you are getting confussed between Power Query "M" and DAX.
They are 2 different programming languages and handles spaces differently

 

Blank() is a DAX command


You can learn Power Query "M" by clicking the column arrow and then apply or remove filters.

speedramps_0-1739391533282.png

the M code is then displayed ...

speedramps_1-1739391592897.png

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors