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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
m080p695
New Member

Creating a new measure from date ranges

Hi, I have been struggling with trying to figure out how to create a new categorical measure based on date ranges within another column. For example, I have the column [request_date] with single date entries. I am trying to create a new measure [grant year] that takes a range of dates (for example, 2022-07-01 to 2023-06-30) and recodes those as "year 1" 

 

Copilot gave me the DAX code

Year =
SWITCH(
    TRUE(),
    'PBI vwFrontiers_Consultation_Request'[request_date] >= DATE(2022,7,1) && 'PBI vwFrontiers_Consultation_Request'[request_date] <= DATE(2023,6,30), "Year 1",
    'PBI vwFrontiers_Consultation_Request'[request_date] >= DATE(2023,7,1) && 'PBI vwFrontiers_Consultation_Request'[request_date] <= DATE(2024,6,30), "Year 2",
    'PBI vwFrontiers_Consultation_Request'[request_date] >= DATE(2024,7,1) && 'PBI vwFrontiers_Consultation_Request'[request_date] <= DATE(2025,6,30), "Year 3",
    'PBI vwFrontiers_Consultation_Request'[request_date] >= DATE(2025,7,1) && 'PBI vwFrontiers_Consultation_Request'[request_date] <= DATE(2026,6,30), "Year 4",
    'PBI vwFrontiers_Consultation_Request'[request_date] >= DATE(2026,7,1) && 'PBI vwFrontiers_Consultation_Request'[request_date] <= DATE(2027,6,30), "Year 5",
    "Outside Grant Period"
)

but whenever I input it, I get a syntax error. Either it doesn't recognize the variable "request_date" or says that Switch() is not a recognized function. 

1 ACCEPTED SOLUTION
Kedar_Pande
Super User
Super User

Create a calculated column, not a measure.

 

Grant Year =
SWITCH(TRUE(),
'PBI vwFrontiers_Consultation_Request'[request_date] >= DATE(2022,7,1) &&
'PBI vwFrontiers_Consultation_Request'[request_date] <= DATE(2023,6,30), "Year 1",
'PBI vwFrontiers_Consultation_Request'[request_date] >= DATE(2023,7,1) &&
'PBI vwFrontiers_Consultation_Request'[request_date] <= DATE(2024,6,30), "Year 2",
"Outside Grant Period"
)

 

Add more date ranges as needed.

 

View solution in original post

7 REPLIES 7
v-pnaroju-msft
Community Support
Community Support

Thankyou, @lbendlin, @DataNinja777, @Praful_Potphodeand @Kedar_Pande for your responses.

Hi m080p695,

We appreciate your inquiry through the Microsoft Fabric Community Forum.

We would like to inquire whether have you got the chance to check the solutions provided by @lbendlin, @DataNinja777, @Praful_Potphode and @Kedar_Pande to resolve the issue. We hope the information provided helps to clear the query. Should you have any further queries, kindly feel free to contact the Microsoft Fabric community.

Thank you.

Kedar_Pande
Super User
Super User

Create a calculated column, not a measure.

 

Grant Year =
SWITCH(TRUE(),
'PBI vwFrontiers_Consultation_Request'[request_date] >= DATE(2022,7,1) &&
'PBI vwFrontiers_Consultation_Request'[request_date] <= DATE(2023,6,30), "Year 1",
'PBI vwFrontiers_Consultation_Request'[request_date] >= DATE(2023,7,1) &&
'PBI vwFrontiers_Consultation_Request'[request_date] <= DATE(2024,6,30), "Year 2",
"Outside Grant Period"
)

 

Add more date ranges as needed.

 

Thank you! You are correct. I needed to create a new column not a new measure. This worked for me. 

If this answer helped, please click Kudos or mark as Solution.
-Kedar
LinkedIn: https://www.linkedin.com/in/kedar-pande

Praful_Potphode
Resolver III
Resolver III

@m080p695 

The reasonyou are getting error is because measure expects single/scalar value. in your expression, column is being compared with a single date value.  it is not able to convert your expression to single/scalar value.instead of using request_date column try to put it in some aggregation like min ,max etc. and try again.

Year =
SWITCH(
    TRUE(),
    MIN('PBI vwFrontiers_Consultation_Request'[request_date]) >= DATE(2022,7,1) && 
    MIN('PBI vwFrontiers_Consultation_Request'[request_date]) <= DATE(2023,6,30), "Year 1",
    MIN('PBI vwFrontiers_Consultation_Request'[request_date]) >= DATE(2023,7,1) 
 && MIN('PBI vwFrontiers_Consultation_Request'[request_date])<= DATE(2024,6,30), "Year 2",
    MIN('PBI vwFrontiers_Consultation_Request'[request_date])>= DATE(2024,7,1) 
 && MIN('PBI vwFrontiers_Consultation_Request'[request_date]) <= DATE(2025,6,30), "Year 3",
    MIN('PBI vwFrontiers_Consultation_Request'[request_date]) >= DATE(2025,7,1) 
 && MIN('PBI vwFrontiers_Consultation_Request'[request_date]) <= DATE(2026,6,30), "Year 4",
    MIN('PBI vwFrontiers_Consultation_Request'[request_date]) >= DATE(2026,7,1) 
 && MIN('PBI vwFrontiers_Consultation_Request'[request_date])<= DATE(2027,6,30), "Year 5",
    "Outside Grant Period"
)

Please give kudos or mark it as solution once confirmed.

 

Thanks and Regards,

Praful

DataNinja777
Super User
Super User

Hi @m080p695 ,

 

In order to create what you require, you can create a calculated column like below:

Grant Year = 
VAR d = Requests[request_date]
VAR fyStart = DATE ( YEAR(d) - IF ( MONTH(d) < 7, 1, 0 ), 7, 1 )
VAR yrs = YEAR(fyStart) - 2022
RETURN
IF(
    d < DATE(2022,7,1) || d > DATE(2027,6,30),
    "Outside Grant Period",
    "Year " & (yrs + 1)
)

The resultant output in table visual is as shown below:

DataNinja777_0-1761404270826.png

Please find attached the pbix file for your reference.

 

Best regards,

 

 

lbendlin
Super User
Super User

If you want a measure then you need some sort of aggregation for your request_date  value.

 

For a shorter version you can use CALENDAR

Year =
SWITCH(
    TRUE(),
    'PBI vwFrontiers_Consultation_Request'[request_date] IN CALENDAR("2022-07-01","2023-06-30"), "Year 1",
   ...,
    "Outside Grant Period"
)

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.