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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
nick011
Frequent Visitor

Custom Decimal Places

Hello, Looking for a Power Query function similar to MySQL Format() - formats a number to a format like "#,###,###. ##", rounded to a specified number of decimal places, then it returns the result as a string.

 

I have a value column, and a column that states how many decimal places that row value should have. 

 

I need a function that applies that number of decimal places.

1 ACCEPTED SOLUTION
nick011
Frequent Visitor

Thank you. I actually got what was needed from just this bit 

 

Number.Round([PrimaryValue],[DecimalPlaces]))

View solution in original post

5 REPLIES 5
nick011
Frequent Visitor

Thank you. I actually got what was needed from just this bit 

 

Number.Round([PrimaryValue],[DecimalPlaces]))

That's great 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






bhanu_gautam
Super User
Super User

@nick011 , You can use below mentioned M-Code in Custom column to modify format

 

FormattedValue = Text.FromNumber([Value], "0." & Text.Repeat("0", [DecimalPlaces]))

 

Value is the numeric value to be formatted

Decimal Places is the number of decimal places to format the value to




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks for your quick response. However, the following error message was received.

 

"Expression.Error: The name 'Text.FromNumber' wasn't recognized. Make sure it's spelled correctly"

 

 

Try this one 

 

FormattedValue =
let
value = [Value],
decimalPlaces = [DecimalPlaces],
roundedValue = Number.Round(value, decimalPlaces),
textValue = Text.From(roundedValue),
decimalPointIndex = Text.PositionOf(textValue, "."),
formattedValue = if decimalPointIndex = -1 then
textValue & "." & Text.Repeat("0", decimalPlaces)
else
textValue & Text.Repeat("0", decimalPlaces - (Text.Length(textValue) - decimalPointIndex - 1))
in
formattedValue




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors