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

DAX - Variant Data Type error IF statement

Hi all,

 

I am writing a DAX formula to return a text result ("NED", which means "not enough data") if a quantity on hand of an item is less than a certain amount.  However, if it is true, then it should return the numerical data.  I don't care if the data is actually stored as a number or a string, however, as I am just displaying it in a card in Power BI desktop.  Though the data IS numerical in previous calculations (hence why this final calculation is called "Calc4_qOH").  Here's my query:

 

EstQtyOH = IF(InvAnalytics[Calc4_qOH] < 2, "NED", InvAnalytics[Calc4_qOH])

 

I receive the error "Expressions that yield variant data-type cannot be used to define calculated columns."

 

If I change "NED" to a number, the IF statement works.  I tried SWITCH as well, but didn't get any further than if I used IF.  Am I doing something wrong and my request is possible, or is my request impossible for DAX?  Again, I am still learning DAX as I go.  Many thanks in advance!

 

- Derek

 

1 ACCEPTED SOLUTION

Hey,

 

try this 

 

IF(
  AND(
    InvAnalytics[Calc4_qOH] >= 2 
    ,NOT ISBLANK(InvAnalytics[Calc4_qOH])
  )
  ,FORMAT(InvAnalytics[Calc4_qOH], "#.##")
  , "NED"
) 

 

this could be an alternative

 

IF(
  AND(
    InvAnalytics[Calc4_qOH] >= 2 
    ,InvAnalytics[Calc4_qOH] <> ""
  )
  ,FORMAT(InvAnalytics[Calc4_qOH], "#.##")
  , "NED"
)

 

BLANK() returns a BLANK() meaning NULL value whereas ISBLANK(...) checks if a column reference is empty

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

18 REPLIES 18

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.