知識庫

How to calculate the average of Top N %


發佈時間 : 07 Apr 2022
上次修改日期 : 11 Apr 2022

問題

How to Calculate the Top N% Average

環境

  • Tableau Desktop

答案

The steps below are to calculate the average of the top 10% of sales per Customer Name.

1. Connect to Sample -Superstore.
2. Create a new Calculated Field as following setting.
       Name : Top10
       Calculation : INDEX() <= INT(SIZE()/10)
                           //This is Table Calculation Filter to narrow down the Top10%.
3. Create a new Calculated Field like below.
       Name : Top10_Average
       Calculation :if first()=0 then
                           window_avg ( if [Top10] then
                           sum([Sales])
                           end)
                           END
4. Drag [Customer Name] to Detail.
5. Drag [Top10_Average] to Text.
6. Right-click on [Customer Name] in Mark Card > Sort > Setting as following.
User-added image
7. Right-click on [Top10_Average] in Mark Card > Edit Table Calculation > Setting as following.
User-added image

You would see Top 10 averages 
這篇文章是否解決了問題?