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! Learn more

Reply
Yxalitis
Helper I
Helper I

Selectively show decimal places only if requires in Matrix

I display metrics in a matrix, some of these are percentages, i.e. % system uptime.

This matrix is a rolling 6 month, using this code (which works fine)

Previous Months % Availability BC1 =
 
VAR NumOfMonths = -6
VAR ReferenceDate = MAX ( 'Date Table'[Date] )
VAR PreviousDates =
    DATESINPERIOD (
        'Previous Dates'[Date],
        ReferenceDate,
        NumOfMonths,
        MONTH
    )
VAR Result =
    CALCULATE (
        [% Availability BC1],
        REMOVEFILTERS ( 'Date Table' ),
        KEEPFILTERS ( PreviousDates ),
        USERELATIONSHIP ( 'Previous Dates'[Date], 'Date Table'[Date] )
    )
RETURN  Result
 
As this is a percentage, I select that option from the measure's Format properties. 
However, I can only choose a set umber of decimal places.
However, for neatness, I want to only show the decimapl places when needed.
I.e. NOT:
100.00% | 99.99%
But
100% | 99.99%
Is there a simply way to achieve this witout trying to add a conditional to the 'result' return?
I mean I could use a complex Switch statement that checks for whole number results, and returns either a whole number or decimal, but that would be very complex thing to try and incorporate into my measure's Return result.
 
So before I go down that rabbit hole, is there a simpler way to achieve this?
1 ACCEPTED SOLUTION
Yxalitis
Helper I
Helper I

Solved it this way,
Replaced the last 'result' with

IF(LEN(CONVERT(result,STRING))>4,FORMAT(result,"Percent"),FORMAT(result,"###%")
Works great!

View solution in original post

4 REPLIES 4
Yxalitis
Helper I
Helper I

Solved it this way,
Replaced the last 'result' with

IF(LEN(CONVERT(result,STRING))>4,FORMAT(result,"Percent"),FORMAT(result,"###%")
Works great!
Ritaf1983
Super User
Super User

HI @Yxalitis 

If you're looking for an option to format the number of decimal places conditionaly based on measure value directly from the interface, it doesn't exist.
To format the number of decimals in a measure, you can use the Dynamic String Formatting feature.
Here’s a guide with instructions:

https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-dynamic-format-strings

It's important to note that from an effective visualization perspective, this approach is not recommended in the same visualization.
Our brain (subconsciously) perceives a wider number (with more decimal places) as larger than a narrower one (with fewer decimals).
As a result, when decimal formatting varies, it creates unnecessary cognitive load, requiring the viewer to stop and recompare,
which increases the likelihood of misinterpretation.

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

"It's important to note that from an effective visualization perspective, this approach is not recommended in the same visualization.
Our brain (subconsciously) perceives a wider number (with more decimal places) as larger than a narrower one (with fewer decimals).
As a result, when decimal formatting varies, it creates unnecessary cognitive load, requiring the viewer to stop and recompare,"


Well, I don't think that's true, 100% is clearer than 100.00% IMHO

Thanks, I solved it via an embedded switch statement.

Anonymous
Not applicable

Hi @Yxalitis ,

It's glad to hear that your problem has been resolved. And thanks for sharing the solution here. It would be helpful to others in the community if they face the similar problem as yours. Thank you.

Best Regards

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