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
AmaGreen
Frequent Visitor

Switch.. True gives error when I save my Power BI file

Dear Community, 
I am having an issue with my Switch True function.
I want to create a string column out of an integer column.
The DAX functio is seen below.
It works fine and I can use it to develop my visuals. 

Age_range = SWITCH( True(),
'Main practice adopted'[Age_in_adopt] = BLANK() , " ",
'Main practice adopted'[Age_in_adopt] <18, "Young",
'Main practice adopted'[Age_in_adopt] >= 18 && 'Main practice adopted'[Age_in_adopt] <=35, "Youth",
'Main practice adopted'[Age_in_adopt] >=35, "Old")


The issue: when I click on the "Save"button to close my Power BI desktop, I get an error;
The syntax for '"Young"' is incorrect. (DAX(SWITCH( True(),'Main practice adopted'[Age_in_adopt] = BLANK() , " ",'Main practice adopted'[Age_in_adopt] <18. "Young",'Main practice adopted'[Age_in_adopt] >= 18 && 'Main practice adopted'[Age_in_adopt] <=35. "Youth",'Main practice adopted'[Age_in_adopt] >=35. "Old"))).

I tried using IF functions too, the same error happened.
Kindly help me on how to go about the error.
Thank you

1 ACCEPTED SOLUTION

@AmaGreen Well, it is indeed strange. I recreated the data and the column and no issues saving. What versino of the Desktop are you on? I attached my PBIX, perhaps you can open it and try saving it and see if you get the error?

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
AmaGreen
Frequent Visitor

@Greg_Deckler I am sharing the data file with you.
Due to confidentailty, I cannot share the file publicly.
Thanks for understanding.

Select_benefic.registered_yearSelect_benefic.pull_genderSelect_benefic.pull_dateSelect_benefic.pull_idcode_noteSelect_benefic.pull_idAdoptPractices.AdoptedpractAdoptPractices.NoadoptionAdoptPractices.essentpractiseAdoptPractices.essentialpract_numbAdoptPractices.two_morepracticeAdoptPractices.whataddoptedAdoptPractices.whataddopted_numbAdoptPractices.whatadopted_otherAdoptPractices.whataddopted_numb_noteAdoptPractices.practicesoneareaAdoptPractices.whatadd_note_numberAdoptPractices.practice_countGender_in_adoptGender_adoptedAge_in_adoptAge_range
 Male03/10/2023 12:06:30  Yes Use_of_improved_seeds1YesManual_ploughing Sowing_compass_and_density_(intercropping_spacing)2  Yes  MaleMale33Youth
2023Male26/10/2023 08:55:37  Yes integrated_pest_mgt1NoDrip_irrigation Irrigation_with_sprinklers2  No 2Male 49Old
OtherMale03/10/2023 12:06:30 3701184870140No  0  0     Female 40Old
 Male03/10/2023 12:06:30  Yes water_management Use_of_improved_seeds Crop_rotation3YesUse_of_pedestral_pump_for_irrigation Transport_by_open_channel_to_the_field Transport_by_closed_channel_(pipes)_to_the_field3  Yes      
2023Female26/10/2023 09:31:28  Yes mulching integrated_pest_mgt2YesManual_ploughing Ploughing_with_animal_traction Land_preparation_with_sulches3  Yes  FemaleFemale38Old

@AmaGreen Well, it is indeed strange. I recreated the data and the column and no issues saving. What versino of the Desktop are you on? I attached my PBIX, perhaps you can open it and try saving it and see if you get the error?

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you.
I copied and pasted yours.
I don't know why it didnt work for me.
I use Power BI desktop version: 2.124.2028.0 64-bit (December 2023)

@AmaGreen Yep, that's the same one I use. Super weird.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@AmaGreen That's very strange. Any chance you can share the PBIX file?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.