Why is table totals not adding up for hardcoded values?
What do you mean by “hardcoded values” here? I bet the answer lies in the SQL being executed. If you check out the SQL tab on that explore (maybe simplify the explore down to be just the Collection Officer Target field for readability), what’s the totals query look like?
It should show as a separate query following a comment in the SQL.
Hi Izzi
no, I mean if in your visualisation you create a table calculation and hardcode the value. Then those values dont add up in a table. The total is either missing or shows zero (as in my screen shot above).
it’s probably because looker consider your hardcoded value as a dimension and not a measure, hence not computing the total.
To correct that make it a sum.
hmmm…
so what I have is this:
if(${Officer.name} = “Louie”, 420000,
if(${Officer.name} = “Henry”, 300000,
if(${Officer.name} = “Caitlin”, 420000,
if(${Officer.name} = “Lauryn”, 420000,
if(${Officer.name} = “Hayley”, 420000, 0)))))
so I’ve tried
if(${Officer.name} = “Louie”, sum(420000),
if(${Officer.name} = “Henry”, sum(300000),
if(${Officer.name} = “Caitlin”, sum(420000),
if(${Officer.name} = “Lauryn”, sum(420000),
if(${Officer.name} = “Hayley”, sum(420000), sum(0))))))
but that gives me some really wonky results.
Hmm, sorry I honestly thought that would fix the problem but it seems that only table calc based on measures can have a total. Table calc based on dimensions (or hard coded values for that matter) won’t show in a row total.
Thanks, Adam
Funny enough
And (I’m no expert so might be way off but) would I then be right in thinking adding table calcs don’t actually change the SQL, they just apply to the visualisation, so in this case if
This might works, but it doesnt look nice. My business users dont like it.
They just want the total at the bottom.
and I dont want to put this in LookML, as I want the team lead to be able to edit the tile and change the values.
Thanks, Adam
You’re right
You are all correct, here!
Table calculations execute in the frontend, in javascript-- Which is why you can do some crazy cool stuff with them. They do not appear in the SQL (there are a few specific exceptions) so I was totally off-base with my advice to check the SQL. I didn’t know it was a table calc.
There is a workaround here. Cyril is correct that there are “Dimension table calcs” and “Measure table calcs” that have different behavior. The key here is that we need to trick Looker into thinking that your hardcoded dimension table calc is a measure table calc, and it’s pretty easy to do that.
- Add a measure to your explore (any measure will do, it doesn’t matter. Maybe something performant 🙂 )
- Write your table calculation as `hardcodedvalue + (${view.dummy_measure}*0)
- Save, and observe your total! You’ll want to select “Hide from Visualization” on the dummy measure.
Simply by referencing a measure in the table calculation expression, that calc becomes a “measure table calc”-- Even if you’re just adding 0 to your hardcoded value by multiplying the measure * 0.

Thanks
Thanks, Adam
I’ve also tried to add
+ (${amount}*0)
into the table calculation, but this puts that column into each of the pivot columns, and also still doesnt add up.

where, I want this column to only show on the left like this:

You’re completely right. I don’t think there is a way to get this to work for a “hardcoded value” given the way that we calculate totals (see: https://help.looker.com/hc/en-us/articles/360001285527-Why-Don-t-My-Totals-Match-the-Values-in-my-Table- for reference). This is a great point and something I’ll flag internally.
Ah. Ignoring the glaring issue that I just mentioned above, this is still possible I think, by adding a pivot_where() function to the table calculation. That will remove it from the pivot columns and let you move it around as needed in the new table viz. But the totals issue still stymies this one.
Reply
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.