Power BI: TopN and All Other

我的梦境 提交于 2019-11-28 10:14:50

This can be done by creating a rank measure, then use it to determine the first N types and the succeeding ones.

Create this measures:

Total:=SUM(Data[Amount])

Create the [Type Rank] measure using the [Total] measure:

Type Rank:=RANKX(ALL(Data[Type]);[Total])

Now use [Type Rank] measure to determine when aggregate the [Amount].

Top3:=IF ([Type Rank] <= 3;[Total];
  IF(HASONEVALUE(Data[Type]);
    IF(VALUES(Data[Type]) = "Others";
       SUMX ( FILTER ( ALL ( Data[Type] ); [Type Rank] > 3 ); [Total] )
    ) 
  ) 
)

Replace the 3 ocurrences by the number of Types you want to get. Also note Data is the name of the table in my example, you have to put the actual table name.

It is necessary to add Others row to your data to then put the aggregation of the greather than N types, so you can use something like this:

Year    Location    Type    Amount
2015    West        Apple   12
2015    West        Pear    14
2015    East        Apple   55
2015    South       Orange  62
2015    West        Orange  64
2015    East        Banana  12
2015    North       Banana  23
2015    East        Peach   43
2015    East        Apple   89
2015    West        Banana  77
2015    West        Orange  43
2015    North       Apple   2
2015    East        Others  

This is a pivot table I've created using your data in Excel:

This is the calculated rank for every value in the Types column:

This approach can be used in Power BI too.

Let me know if this helps you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!