We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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.
Solved! Go to Solution.
Thank you. I actually got what was needed from just this bit
Number.Round([PrimaryValue],[DecimalPlaces]))
Thank you. I actually got what was needed from just this bit
Number.Round([PrimaryValue],[DecimalPlaces]))
That's great
Proud to be a 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
Proud to be a Super User! |
|
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
Proud to be a Super User! |
|
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 11 | |
| 10 | |
| 7 | |
| 6 | |
| 5 |