Reply
Frequent Visitor
Posts: 6
Registered: ‎03-15-2017
Accepted Solution

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

 


Accepted Solutions
Highlighted
Super Contributor
Posts: 1,178
Registered: ‎07-09-2016

Re: Number Formatting Function


All Replies
Highlighted
Super Contributor
Posts: 1,178
Registered: ‎07-09-2016

Re: Number Formatting Function

@rgodfrey,

 

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

Frequent Visitor
Posts: 14
Registered: ‎06-02-2017

Re: Number Formatting Function

@rgodfrey,

 

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.

 

Frequent Visitor
Posts: 6
Registered: ‎03-15-2017

Re: Number Formatting Function

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

Frequent Visitor
Posts: 14
Registered: ‎06-02-2017

Re: Number Formatting Function

thanks a lot @rgodfrey. that helped.