2016-09-11 17 views
-1
How to write the DAX query for top n records and rest of records should be others? 

Example:- 

Table name sample 

col1  col2 
-------------- 
a  10 
b  20 
c  30 
d  40 
e  50 
f  60 

I need output like top 3 records rest of should be "others" 
like 
     col1  col2 
     ------------------- 
      a   10 
      b   20 
      c   30 
      others  150 
     ------------------- 

    Can anyone please help on this. Thanks in advance. 
+0

檢查[這個答案](http://stackoverflow.com/a/38089892/2647648)我發佈了一個非常類似的問題。 –

回答

0

它需要動態嗎?如果沒有,你可以做懶惰的方式

evaluate ( 
summarize ( 
      sample, 
      if(pathcontains("a|b|c", sample[col1]) = false(), 
       "others", 
       sample[col1] 
       ), 
    "col2", sum(sample[col2]) 
      ) 
    ) 

order by 
sample[col1] 
相關問題