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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

switch

Hello,
I would like to add a column to an existing table in the model but the error is below. Any suggestions please?:

 

Function 'SWITCH' does not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

note that [CalendarQuarterKey] is int and holds values such as:
20153
20154
...
20201
...

StartMonthDayKey =
SWITCH(
'myDate'[CalendarQuarterKey],
1, LEFT('myDate'[CalendarQuarterKey], 4) & "0105"),
2, LEFT('myDate'[CalendarQuarterKey], 4) & "0405"),
3, LEFT('Date'[CalendarQuarterKey], 4) & "0705"),
4, LEFT('myDate'[CalendarQuarterKey], 4) & "1005")
)

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Anonymous 

try CONVERT()

StartMonthDayKey =
var _CalendarQuarterKey = LEFT(CONVERT('myDate'[CalendarQuarterKey], STRING), 4)

RETURN 

SWITCH(
'myDate'[CalendarQuarterKey],
1, _CalendarQuarterKey  & "0105"),
2, _CalendarQuarterKey  & "0405"),
3, _CalendarQuarterKey  & "0705"),
4, _CalendarQuarterKey  & "1005")
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

6 REPLIES 6
danextian
Super User
Super User

Hi @Anonymous,

 

Text functions do not work on numbers. To be able to use a number as a text it has to be converted first to text using FORMAT function. For example:

Text to Number =
FORMAT ( 'Table'[NumberField], "#" )

 

In your case, you can store the text version of myDate'[CalendarQuarterKey] in a variable and use that in SWITCH instead. You also need to remove the extra closing parenthesis after each "01##" as they will cause a syntax error.

StartMonthDayKey =
VAR TextToNumber =
    FORMAT ( 'myDate'[CalendarQuarterKey], "#" )
RETURN
    SWITCH (
        'myDate'[CalendarQuarterKey],
        1, LEFT ( TextToNumber, 4 ) & "0105",
        2, LEFT ( TextToNumber, 4 ) & "0405",
        3, LEFT ( TextToNumber, 4 ) & "0705",
        4, LEFT ( TextToNumber, 4 ) & "1005"
    )

 Also





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

 
Anonymous
Not applicable

For the following DAX, the error is:
Function 'SWITCH' does not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

StartQuarterYearMonthDayKey =
VAR TextToNumber =
FORMAT ( left('Date'[Calendar Quarter Key], 4), "#" )
RETURN
SWITCH (
'Date'[CalendarQuarterKeyValue],
1, LEFT ( TextToNumber, 4 ) & "0105",
2, LEFT ( TextToNumber, 4 ) & "0405",
3, LEFT ( TextToNumber, 4 ) & "0705",
4, LEFT ( TextToNumber, 4 ) & "1005"
)

az38
Community Champion
Community Champion

Hi @Anonymous 

try CONVERT()

StartMonthDayKey =
var _CalendarQuarterKey = LEFT(CONVERT('myDate'[CalendarQuarterKey], STRING), 4)

RETURN 

SWITCH(
'myDate'[CalendarQuarterKey],
1, _CalendarQuarterKey  & "0105"),
2, _CalendarQuarterKey  & "0405"),
3, _CalendarQuarterKey  & "0705"),
4, _CalendarQuarterKey  & "1005")
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

, still getting error:

The syntax for ',' is incorrect. (DAX(var _CalendarQuarterKey = LEFT(CONVERT('Date'[Calendar Quarter Key], STRING), 4)RETURN SWITCH('Date'[CalendarQuarterKeyValue],1, _CalendarQuarterKey & "0105"),2, _CalendarQuarterKey & "0405"),3, _CalendarQuarterKey & "0705"),4, _CalendarQuarterKey & "1005")))).

az38
Community Champion
Community Champion

@Anonymous 

sorry, wrong parenthesys

StartMonthDayKey =
var _CalendarQuarterKey = LEFT(CONVERT('myDate'[CalendarQuarterKey], STRING), 4)

RETURN 

SWITCH(
'myDate'[CalendarQuarterKey],
1, _CalendarQuarterKey  & "0105",
2, _CalendarQuarterKey  & "0405",
3, _CalendarQuarterKey  & "0705",
4, _CalendarQuarterKey  & "1005"
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.

Top Solution Authors