Change the table cell color based on value

Hi, Where your writing this code on table??

Hi,
I want exactly like this but I want sum for only for 2 columns.
I have power table, applied named query to get values from db.
after that How Can I to grand total as in pic. where we need to write this code on table.

image

Hi.
not in table. i have return it in project library script as function. then i am calling it