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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Number Formatting Function

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

 

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

Based on my research, you may use valueFormatter module in Formatting Utils.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

Based on my research, you may use valueFormatter module in Formatting Utils.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@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.

 

Anonymous
Not applicable

@abhay03

 

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?

v-viig
Community Champion
Community Champion

@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

pbicvsupport@microsoft.com

@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

thanks a lot @rgodfrey. that helped.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.