Forum Discussion
How to show values with their default format?
- 3 years ago
Hi Anonymous,
The metadata hasn't changed, but the powerbi-visuals-utils-formattingutils would have gone through a big change around the time this video was made (as they got moved to ES modules, which changes how they are imported).
The docs have an updated set of examples that you should be able to use in order to get the syntax you need to import and call the valueFormatter.
In short, you will need to create a formatter using the measure or column metadata's format property, e.g.:
If there is no format property, it will treat the format string as empty and just format it as a plain number.
If you want to auto-scale, you pass in the value parameter with the value of the number you wish to format. You can see examples of this in the linked doc under the thousand, million, billion and trillion examples. Formatting utils will apply the unit based on your locale. You can make this work as 'auto' (like core charts do) by passing in your measure value instead of a fixed value.
For percentages, as long as your format property contains a valid format string, this will work also. Alternatively, you can construct a format string manually in your code and pass this to the valueFormatter.
Regards,
Daniel