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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ArchStanton
Impactful Individual
Impactful Individual

Variable not working

Hi,

 

I have inherited a data model that has dozens of Ages Banding calculations that I want to simplify using Variables. Is this possible on the code below? Please not the error message below.

 

Age Profile (Creation Months) = 

VAR Age_Profile = 'Cases'[Case Length (Adj)]
RETURN
SWITCH(
    Age_Profile < 90 , " 0-3 Months",
    Age_Profile < 180, " 3-6 Months",
    Age_Profile < 270, " 6-9 Months", 
    Age_Profile < 365, " 9-12 Months", 
            "12+ Months"
)

 

ArchStanton_0-1665070688348.png

Thanks,

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@ArchStanton , Try like

 

VAR Age_Profile = 'Cases'[Case Length (Adj)]
RETURN
SWITCH(true(),
Age_Profile < 90 , " 0-3 Months",
Age_Profile < 180, " 3-6 Months",
Age_Profile < 270, " 6-9 Months",
Age_Profile < 365, " 9-12 Months",
"12+ Months"
)

 

 

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

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@ArchStanton , Try like

VAR Age_Profile = 'Cases'[Case Length (Adj)]
RETURN
SWITCH(true(),
Age_Profile < 90 , " 0-3 Months",
Age_Profile < 180, " 3-6 Months",
Age_Profile < 270, " 6-9 Months",
Age_Profile < 365, " 9-12 Months",
"12+ Months"
)

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

Thanks, I see I omitted TRUE 

It works now!👍

amitchandak
Super User
Super User

@ArchStanton , Try like

 

VAR Age_Profile = 'Cases'[Case Length (Adj)]
RETURN
SWITCH(true(),
Age_Profile < 90 , " 0-3 Months",
Age_Profile < 180, " 3-6 Months",
Age_Profile < 270, " 6-9 Months",
Age_Profile < 365, " 9-12 Months",
"12+ Months"
)

 

 

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.