This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
In my custom visual, I'm trying to get the format from a measure. This passes the format of the measure to the ts file:
dataViews[0].categorical.values[0].source.format
It produces a value like: '0.0 %;-0.0 %;0.0 %' for a percent with 1 decimal and '\$#,0;(\$#,0);\$#,0' for a dollar amount.
My question is, how do I apply that to a number? There has to be a standard function, right?
Thanks
Solved! Go to Solution.
@Anonymous,
Based on my research, you may use valueFormatter module in Formatting Utils.
@Anonymous,
Based on my research, you may use valueFormatter module in Formatting Utils.
@Anonymous,
Did you managed to get the formatting in your visual, I am in the exact same situation.
I am using the valueFormatter but receiving error "Cannot read property 'valueFormatter' of undefined" in console even for the examples here.
I did get it working. This is an example of how I used it:
import valueFormatter = powerbi.extensibility.utils.formatting.valueFormatter;
kpiNumber = valueFormatter.create({
format: categorical.values[kpiRef].source.format,
value: 1001,
precision: settings.kpi.decimalPlaces
});
kpiNumber.format(kpi)Good luck!
@Anonymous I implemented your code and it works. However, the formatting doesn't change once the visual is displayed. For example, I have a number formatted as a decimal number with 3 decimal places. My custom visual shows this value correctly when I use it. But if I change the format to Percentage in the Modelling menu, it doesn't reflect. Did you face the same issue?
@satishr How do you get column format? Do you categorical.values[valueColumnIndex].source.format to get a column format?
Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals
@v-viigYes, I'm using categorical.values[valueColumnIndex].source.format to get the format values. I found out that sometimes this value is not available initially. So I had to put a check for its availability before getting the value. Now it works fine. Thanks
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |