Find percentage of value with respect to another value in the same column

Hello Good Lookers!

So, a lot of times you want to check how much all values are with respect to another value in the same column and not with respect to the total.

For example, here - 

36269584-ad93-4b2c-950d-2e6390554814.png

You may want to check how must representatives do other states have with respect to California (US-CA).

This can be achieved in Looker by having a series of dependent table calculations (3 to be precise).

:point_up: Step 1 - In the first step, we create a table calculation and set the value to 0 for all the rows except the row of interest. Here, we will set the value to 0 for all the rows except “US-CA”. The first table calculation would look like - 

​if(${us_statewise_representatives.code_us}="US-CA",${sum_of_representatives},0)

And the output would look like - 

450975ee-055c-4670-b454-b504af676db0.png

:v: Step 2 - In the second step, we would calculate running total of the table calculation created in Step 1. We can use Looker’s default Running total method and pick the appropriate source field. This is how the results would look like after step 2

cf87d272-1805-4047-9576-ddc4aa32efe1.png

:ok_hand: Step 3 - Finally, we would need to find percentage of the original measure with respect to the table calculation we created in step 2. The table calculation here would look like - 

${sum_of_representatives}/${rt_ca}

And the final output - 

1fb06f4e-aed7-4b2b-bf13-bc91b935839e.png
0 0 853
0 REPLIES 0
Top Labels in this Space
Top Solution Authors