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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
akhilduvvuru
Helper IV
Helper IV

Format Error while displaying numbers and percentages at same time in a table

Hi Team, I have a reqirement to show both numbers and percentages in same column using a measure as below:
I wrote a switch statement in measure

 

Measure = 
VAR _Cat = SELEECTEDVALUE(CATEGORY)
VAR _Apple = CALCULATE(SUM(SALES),REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple"})
VAR _Orange = CALCULATE(SUM(SALES),REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple"})
RETURN
SWITCH (
TRUE (),
_Cat = "Fruits Total", CALCULATE(SUM(FACT_TABLE[SALES]), REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple","Orange"}),
_Cat = "Total %", CALCULATE( FORMAT((_Apple-_Orange)/_Apple,"0.0%"), REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple","Orange"})
)

 

Expected Output:

Category

Sales

Apple22
Orange10
Fruits total33 (Add Apple and Orange)
Total %54.5% (Apple-Orange)/Apple

 

However, my above measure is giving the right result as expected but getting the following conversion error.

 

MdxScript(Model (113, 17) Calculation error in measure 'Measure': Cannot convert value '54.5%' of  type Text to type Numeric/Date.

 


Not sure on how to handle this. Please help me resolving the same. Thanks!

1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @akhilduvvuru ,

 

As a workaround, please try following steps.

 

This is my test table:

vyadongfmsft_1-1668418756662.png

 

Create a new column:

 

Column =
VAR _a = 'Table'[SALES] * 100
VAR _b =
    IF ( 'Table'[CATEGORY] = "Total %", _a, 'Table'[SALES] )
VAR _c =
    CONVERT ( _b, STRING )
RETURN
    IF ( 'Table'[CATEGORY] = "Total %", _c & "%", _c )

 

 

You will get a column like this:

vyadongfmsft_2-1668418850134.png

 

I think this is the result you want:

vyadongfmsft_3-1668418878494.png

 

Please refer the attached pbix file.

 

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yadongf-msft
Community Support
Community Support

Hi @akhilduvvuru ,

 

As a workaround, please try following steps.

 

This is my test table:

vyadongfmsft_1-1668418756662.png

 

Create a new column:

 

Column =
VAR _a = 'Table'[SALES] * 100
VAR _b =
    IF ( 'Table'[CATEGORY] = "Total %", _a, 'Table'[SALES] )
VAR _c =
    CONVERT ( _b, STRING )
RETURN
    IF ( 'Table'[CATEGORY] = "Total %", _c & "%", _c )

 

 

You will get a column like this:

vyadongfmsft_2-1668418850134.png

 

I think this is the result you want:

vyadongfmsft_3-1668418878494.png

 

Please refer the attached pbix file.

 

Best regards,

Yadong Fang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@akhilduvvuru , you can not have two data types in one column. So other one need to a text too, you use format in true result also

 

Measure =
VAR _Cat = SELEECTEDVALUE(CATEGORY)
VAR _Apple = CALCULATE(SUM(SALES),REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple"})
VAR _Orange = CALCULATE(SUM(SALES),REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple"})
RETURN
SWITCH (
TRUE (),
_Cat = "Fruits Total", CALCULATE(SUM(FACT_TABLE[SALES]), REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple","Orange"}) & "",
_Cat = "Total %", CALCULATE( FORMAT((_Apple-_Orange)/_Apple,"0.0%"), REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple","Orange"})
)

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

@amitchandak - Thanks for your quick response. I updated my measure with &"". But not luck it is still showing the same error

 

MdxScript(Model (113, 25) Calculation error in measure 'Measure': Cannot convert value " of  type Text to type Number.

 

I have also added the same thing to else part (populating numbers only) as well. I think this time else part is throwing this above error.

@akhilduvvuru , That is strange

 

tr y like

 

Measure =
VAR _Cat = SELEECTEDVALUE(CATEGORY)
VAR _Apple = CALCULATE(SUM(SALES),REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple"})
VAR _Orange = CALCULATE(SUM(SALES),REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple"})
RETURN
SWITCH (
TRUE (),
_Cat = "Fruits Total", CALCULATE(SUM(FACT_TABLE[SALES]), REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple","Orange"}) & "",
_Cat = "Total %", CALCULATE( FORMAT((_Apple-_Orange)/_Apple,"0.0%"), REMOVEFILTERS(DIM_TABLE), DIM_TABLE[CATEGORY] IN {"Apple","Orange"}) & ""
)

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.