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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Getting error - expressions that yield variant data type cannot be used in calculated column

Hi,

 

I need to display only month values when the date diff between 2 dates is >=90days and display only day values when the date diff is >=4 days, display hour values when the date diff is >= 1 days else display the default date value.

 

To achieve this , I used a calcuated column named Time level as shown below 

 

Time Level = IF(DATEDIFF(min('Fact'[Production Date-Time]),max('Fact'[Production Date-Time]),DAY)>=90,"M",
(IF(DATEDIFF(min('Fact'[Production Date-Time]),max('Fact'[Production Date-Time]),DAY)>=4,"D",
(IF(DATEDIFF(min('Fact'[Production Date-Time]),max('Fact'[Production Date-Time]),DAY)>=1,"H","E")))

 

After that i tried using the time level column into another calculated column , when i used the day function, am getting the variant data type error. Please help.Variant datatype.PNGVariant datatype issue -1.PNG

 

custom date xaxis = if ('Fact'[Time Level] = "M",'Fact'[Production Date-Time].[Month],
(if('Fact'[Time Level]="D",'Fact'[Production Date-Time].[Day],'Fact'[Production Date-Time])))
3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@Anonymous 

 

You may try adding CONVERT.

        IF (
            'Fact'[Time Level] = "D",
            CONVERT ( 'Fact'[Production Date-Time].[Day], STRING ),
            CONVERT ( 'Fact'[Production Date-Time], STRING )
        )

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi,

 

I used the convert function and now my clculated column does not throw the variant data type error but its not displaying the correct value, its diaplaying H by default. Ideally if the timelevel selection is "M" only month value should be displayed, when the time level is "D" it should display days but it is always dispalying "H".

Please find the code below and the screenshot shows the value of timelevel, date diff and the claculated column which is not

showing correctly.

 

test prod date selection = if([Time level]="M",'Fact'[prod-month],
if([Time level]="D",convert('Fact'[prod-day],STRING),"H"))

test prod date selection.PNG

 

 
amitchandak
Super User
Super User

Seem like Day is int and other is text

add & "" after the [Day]

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.