Table Calculations: Different Value Format for Each Row

vsil
New Member

Hello,

I have implemented the table transpose solution described here. However, in the example by Looker, all the measures are in the same value format, that is integer. Is there any hacky solution that would allow having different value formats for each of the dimensions that are in one table calculations column?

In the same Looker example, imagine that the measure Count would be integer and the measure Count Orders would be $. So in the column The Magic, the first row would also be integer but row 3 would be $.

0 2 1,192
2 REPLIES 2

Really manual, hacky, and probably not so elegant solution: There will be some limitations (depending on the types of formatting you end up trying to do in the vis) - but you could do just about any value formatting you want via string functions in your table calc along with some if() conditions. For example, say our data table looks something like:

Metric 2016 2017
Dollars 100 200
Percent .93 .59

You could do something like the following to get the dollars row formatted as $number:

`concat(“$”, to_string(${column}))`

And something like the following to get the percent row formatted as %number:

`concat(“%”, to_string(${column}))`

Now, you need some way of determining which row to do what at, so for that we can use a set of if() statements. I’m being exceptionally lazy, so I’ll use row() in my solution as the condition. 

This will be true at the dollars row: 

`if(row() = 1, ...)

And this will be true at the percent row:

`if(row() = 2, ...)

Putting this all together we get something like:

`if(row() = 1, `concat(“$”, to_string(${column}))`, `if(row() = 2, `concat(“%”, to_string(${column}))`, “none”))

vsil
New Member

@jamesnestler, thanks a lot for your reply! This seems like a nice solution although if the original value has, for example, thousand separator, decimal separator and currency indicator, this will not work.

It would be nice to have exactly the same format as the original value although I understand that the same column with different value formats is kind of ?‍♂️.

Top Labels in this Space
Top Solution Authors