cube icon indicating copy to clipboard operation
cube copied to clipboard

Support percents that are not multiplied by 100.

Open reify-thomas-smith opened this issue 3 years ago • 2 comments

Generally, I want to handle formatting in the front-end code, not in Cube. For instance, if I want to display a number as a percentage in a table, then Cube will provide a ratio measure, and I'll turn it into a percentage string in the table column definition using Intl.NumberFormat. In particular, I expect Cube to provide a raw ratio, not a ratio multiplied by 100. This is consistent with the behavior of both Intl.NumberFormat and Excel, which will both turn .1 into 10% and 10 into 1000%.

However, Cube's percent formatter will format .1 as 0.10% rather than as 10%. This causes incorrect values to be displayed in the playground.

Describe the solution you'd like

Either a new format (e.g. percentNormalized) or a configuration option indicating that percent members are not multiplied by 100.

reify-thomas-smith avatar May 19 '22 16:05 reify-thomas-smith

If you are interested in working on this issue, please leave a comment below and we will be happy to assign the issue to you. If this is the first time you are contributing a Pull Request to Cube.js, please check our contribution guidelines. You can also post any questions while contributing in the #contributors channel in the Cube.js Slack.

github-actions[bot] avatar May 20 '22 11:05 github-actions[bot]

@reify-thomas-smith This is an interesting one

I'll investigate adding a new format, specifically for this, but what my previous company did to work around this. (We also had percentages in decimals)

Is in the cube configuration for this specific metric

percent: { sql: 100.0 * ${percentInDecimal}, type: number, format: percent, },

Just multiple your value by 100 in the sql, you only have to do this once and it will look the same on the frontend.

PieterVanZyl-Dev avatar Jul 12 '22 21:07 PieterVanZyl-Dev