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
Anonymous
Not applicable

DateDiff Help

trying to work on some lead times through by obtaining the difference between 2 dates

 

Committed/Done Diff = IF([DATE1] > [DATE2],"",DATEDIFF([DATE1],[DATE2],DAY))

 

what i am trying to achieve is have if the date 1 is greater than date 2, then leave field as blank

 

if date 1 is not greater than date 2, give me the date difference between the 2 dates

 

the error i get is

"expressions that yield variant data-type cannot be used to define calculated columns"

 

not sure what i am doing wrong

 

any help would be appreciated

1 ACCEPTED SOLUTION
ankitpatira
Community Champion
Community Champion

@Anonymous Reason you're getting this error is because from your IF statement if condition is false then you're returning blank which is of data type text and if true you're returning date. You can't have different data type returns from single IF statement. Therefore if you do conditional column as below it will work.

 

Committed/Done Diff = IF([DATE1] > [DATE2], today(), DATEDIFF([DATE1],[DATE2],DAY))

View solution in original post

2 REPLIES 2
ankitpatira
Community Champion
Community Champion

@Anonymous Reason you're getting this error is because from your IF statement if condition is false then you're returning blank which is of data type text and if true you're returning date. You can't have different data type returns from single IF statement. Therefore if you do conditional column as below it will work.

 

Committed/Done Diff = IF([DATE1] > [DATE2], today(), DATEDIFF([DATE1],[DATE2],DAY))

Anonymous
Not applicable

thanks for the reply

 

that helped but i changed it so i didnt get todays value

 

Committed/Done Diff = IF([DATE1] > [DATE2], Blank(), DATEDIFF([DATE1],[DATE2],DAY))

 

 

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.