Forum Discussion
nick011
2 years agoFrequent 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...
- 2 years ago
Thank you. I actually got what was needed from just this bit
Number.Round([PrimaryValue],[DecimalPlaces]))
nick011
2 years agoFrequent Visitor
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"
bhanu_gautam
2 years agoSuper User
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