cumulative-sumamazon-quicksight

Quicksight running percentage total ordered and aggregated by the same field


I have this dataset and need a cumulative percentage column created (see column 4 of image below).

(https://i.sstatic.net/TFnNn.png)

I've looked at a few solutions and found that using runninsum()/sumover() is the best way to do this. However, the runningsum() function requires an order by input. So based on my data, i need the sum of sales ordered by sales DESC,

runningsum(sum({sales per year}), [{sales per year} DESC]) / sumover(sum({sales per year}))

This doesn't work. The calc field is created, but my table disappears and i'm left with the message - "Table calculation attribute reference(s) are missing in field wells."

Im guessing you cant order by the same field with which you're aggregating, because it works if i replace the order by field with some other field. The problem is, i need the cumulative percentage column to start with the highest sales value.

I've also tried using percentage of total in conjunction with runningtotal(), but it does not work.

Any help is much appreciated.


Solution

  • Hoi Jay Dunna, I think you are correct when you say "Im guessing you cant order by the same field with which you're aggregating". To solve this you need to create a "rank" for the data such as "salesrank" =

    rank([sum({sales per year}) DESC])
    

    Then you can use this to sort your data and do the running sum / sum sales as "Cum perc" =

    runningSum(sum({sales per year}),[salesrank ASC]) / sumOver(sum({sales per year}))
    

    This gives you what you want: enter image description here