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
Anonymous
Not applicable

Metric Switch Formatting Error

I have two metric switch statements. One switch returns the current week data, the other switch is the prior 6 week data. I need to create a Varience between the two, so I need to subtract the two metric switch statements. The issue is that in both metric switch statements, there are 2 measures that need to be formatted as % and I receive an Error: "Cannot convert value '%' of type Text to type numeric/date. I am only formatting the measures to % in the metric switch statements, since metric switchs change data type to default. (Images Below)
Note: The formatting of the % works properly in each individual metric switch, just not when I subtract the switches together.

I am not sure why I am getting this error when the formatting is the same in the two switch statements. I have been able to subtract metric switch statements in other meausres to get Var,  but they didnt have formatting on them.

Is there a workaround for this issue or am I just missing something? Thanks in advance!

Zeegs_2-1629297488934.pngZeegs_1-1629297435631.png

Zeegs_3-1629297531017.png

 

Zeegs_0-1629297413743.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Zeegs_0-1629338640194.png
I just figured out a way to resolve it after trying every possible way. I was able to create a third metric switch statement that did the subtraction and formatting in the last metric switch used. Simple = Difficult haha

Thank you for all your help and suggestions! @Radhika2605 @Fowmy 

 

View solution in original post

9 REPLIES 9
Radhika2605
Helper II
Helper II

@Anonymous Try to enclose your Swtich statement within Value() like -

Value( Switch () ) 

Value will convert text to string and then you should be able to subtract it.

 

Could you please mark this as a solution if this answers your query.

 

Thanks

Radhika

Anonymous
Not applicable

@Radhika2605 
I am still getting the error when I wrap my switch statements in Value(Switch() ). 

Zeegs_2-1629300843694.png

 

Zeegs_1-1629300772423.png

I am trying out your other suggestion

 

Hi @Anonymous If my second option (Is it possible for you to multiply the result of calculation in measures like Cancellation %, Productivity % by 100 and format then using options on the Column Toold Ribbon from the top to say that it is a % instead of using Format function in switch?) doesnt work then we can try to do these things- 
1. Actually what I meant was as you mentioned that switch is converting the data type of result to text so you can do following - 

Value(Switch()) - Value(Swicth) //in your measure where you are subtracting two switches.

 

2. If the above doesnt work then can you please try to use value function outside of the Format functions so that as format is returning a text then it will be converted to Number (not entrierly sure if this will work though).

 

3. to check if switch is converting value to text - I would suggest to do a test. Remove the format  functions so that the result of Cancellation, Productivity and all other measures is number (check the data types too before using them in switch) and then try to subtract it. In this way at least we will know if Switch is causing a problem or Format and can then see what can be done.

 

Thanks

Radhika

 

hope this clarifies.

Anonymous
Not applicable

Zeegs_0-1629338640194.png
I just figured out a way to resolve it after trying every possible way. I was able to create a third metric switch statement that did the subtraction and formatting in the last metric switch used. Simple = Difficult haha

Thank you for all your help and suggestions! @Radhika2605 @Fowmy 

 

Radhika2605
Helper II
Helper II

Hi @Anonymous ,

 

I believe the issue is because the result of Format function is a String and when you are subtracting switch then you are for some values subtracting string from string which is not possible.

 

Is it possible for you to multiply the result of calculation in measures like Cancellation %, Productivity % by 100 and format then using options on the Column Toold Ribbon from the top to say that it is a % instead of using Format function in switch?

 

Could you please mark this as a solution if this answers your query.

 

Thanks

Radhika

Fowmy
Super User
Super User

@Anonymous 

It the data type issue in FORMAT function

Check the cancellation and Productivity measures, are then text ?. use them without FORMAT function.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy Thanks for the response!
Since Metric Switch turn all measures in it to default format "text", I have left Cancellation % and Production % format as "General" in the original meausre. The only place I format them to % is in the Metric Switch. Even if I changed the format in the original measure, the switch statement removes it and turns it to text.

@Anonymous 

When you use FORMAT, the result becomes text, you cannot do calculations on that. 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy Ahh, I did not know that, I thought only the metric switch changed the format of the measures. And if I apply the format to the measures, they should be able to subtract together. Which obviosly it makes sense why its throwing that error now. Thank you.

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.

Top Solution Authors