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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
luckygirl
Helper I
Helper I

Error: expressions that yield variant data types cannot be used to define calculated columns

Hi,

 

I have the following DAX to calculate subsequent date.

 

 

SusequentCompletedDate =
VAR CurrentKey = Table[ClientCode]
VAR CurrentDate = Table[CompletedDate]
VAR NextCompletedDate = CALCULATE (  MIN ( Table[CompletedDate] ) , ALL ( Table), Table[ClientCode] = CurrentKey, Table[CompletedDate] > CurrentDate )
VAR NextG = MINX ( FILTER ( ALL ( Table), AND ( Table[ClientCode] = CurrentKey, Table[CompletedDate] = NextCompletedDate ) ), Table[CompletedDate] )
RETURN IF( NextG <> BLANK(), NextG, "No Subsequent Product" )

It gives me error "expressions that yield variant data types cannot be used to define calculated columns". Can someone let me know why that happens?

 

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @luckygirl 

A DAX expression that is capable of returning different data types under different conditions is deemed to have a "variant" data type.

The Tabular engine does not allow that any column of a table loaded to the model to have a variant data type.

 

The expression for SusequentCompletedDate can return either of:

  1. The variable NextG (which appears to be of type date)
  2. "No Subsequent Product" (type string)

 

I would recommend returning blank rather than a text value when NextG is blank, so you could change the last line to:

RETURN NextG

 

Note that measures are permitted to return variant data types.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

6 REPLIES 6
luckygirl
Helper I
Helper I

Thank you. Return NextG, worked for me. 

OwenAuger
Super User
Super User

Hi @luckygirl 

A DAX expression that is capable of returning different data types under different conditions is deemed to have a "variant" data type.

The Tabular engine does not allow that any column of a table loaded to the model to have a variant data type.

 

The expression for SusequentCompletedDate can return either of:

  1. The variable NextG (which appears to be of type date)
  2. "No Subsequent Product" (type string)

 

I would recommend returning blank rather than a text value when NextG is blank, so you could change the last line to:

RETURN NextG

 

Note that measures are permitted to return variant data types.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Thank you. Yes, understood and Return NextG, worked for me :). 

ArwaAldoud
Super User
Super User

Hi @luckygirl 

The IF statement is returning two different data types NextG, which is a date value and
"No Subsequent Product", which is a text (string) value.
try to use the BLANK() or , you can use a default date eg DATE(1900,1,1)

 

IF( NextG <> BLANK(), NextG, BLANK() )
or
IF( NextG <> BLANK(), NextG, DATE(1900,1,1) )


If this response was helpful, please accept it as a solution and give kudos to support other community members.

Thank you. Return NextG, worked for me. 

Deku
Super User
Super User

In a calculated column to can only have a single data type returned. You are returning a date or string. You could use format( date, "dd-mmm-yy") to cast the date into a string 

 

If this was a measure, variants outputs are possible


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

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.

Top Kudoed Authors