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

New Column using IF and DATESBETWEEN causing Error

I'm trying to create a set of columns that show either the date or null value based off an IF and DATESBETWEEN calculation.   Essentially, I need to create a column for each year that is respresented in the a_CreateDateOnly column.

 

The a_CreateDateOnly column is formatted as a Date.

 

Here is some sample data along with my desired output..

 

 Desired Output
a_CreatedDateOnlya_CDO=2018Onlya_CDO=2017Onlya_CDO=2016Only
6/18/2016 0:00  6/18/2016 0:00
7/11/2016 0:00  7/11/2016 0:00
11/14/2016 0:00  11/14/2016 0:00
11/14/2016 0:00  11/14/2016 0:00
6/18/2017 0:00 6/18/2017 0:00 
6/18/2017 0:00 6/18/2017 0:00 
6/19/2017 0:00 6/19/2017 0:00 
11/14/2017 0:00 11/14/2017 0:00 
6/18/2018 0:006/18/2018 0:00  
6/18/2018 0:006/18/2018 0:00  
6/19/2018 0:006/19/2018 0:00  
6/20/2018 0:006/20/2018 0:00  

 

I created the following formula to try and get my desired output...

 

a_CDO_2018Only = IF(DATESBETWEEN('Case'[a_CreatedDateOnly],DATE(2018,01,01),Date(2018,12,31)),'Case'[a_CreatedDateOnly], "null")

 

This results in the error -  Expressions that yield variant data-type cannot be used to define calculated columns.

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

Just use DAX below.

Column =
IF ( YEAR ( 'Case'[a_CreatedDateOnly] ) = 2018, 'Case'[a_CreatedDateOnly] )
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.

View solution in original post

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

Just use DAX below.

Column =
IF ( YEAR ( 'Case'[a_CreatedDateOnly] ) = 2018, 'Case'[a_CreatedDateOnly] )
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

Thank you Sam!  I guess I tried to make it way too complex.  This worked perfectly.

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.