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
Brysonds
Helper III
Helper III

Assistance with calculation that uses date field

Hi Everyone,

 

I just started using Power BI this week and it's been quite the adventure so far - very cool tool!!

  

I created two columns (one for Year, and one for Month) based on my [Date] field using these formulas:

Year = FORMAT('Sales and Margin Data'[Date], "yyyy")

Month = FORMAT('Sales and Margin Data'[Date], "mmmm")

 

These new fields work great as slicers, etc.  However, if I try to reference these new fields in a measure formula, I get an error that they are not of type [Date] fields. 

 

Is there any way to fix this? I don't want to use the real [Date] field as it limits functionality in slicers, and has no hierachy.

 

 

 

 

2 REPLIES 2
v-sihou-msft
Employee
Employee

@Brysonds

 

In DAX, when using the FORMAT() function, it will return text instead of date. So when you want to use it in time intelligence functions, it will throw the data type error. So if you need to use the date for calculation, just directly use the [Date] column.

 

Regards,

Hi Simon,

 

Thank you very much for the clarification. However, one of the main reasons I am trying to avoid the date field is because it's missing a date hierarcy (it only gives me year). 

 

Is there a way to change the FORMAT() fields from text to date?

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.