Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

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

 

7 Replies

    • abhay03's avatar
      abhay03
      Helper I

      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's avatar
        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!