如何为前n个记录和其他记录编写DAX查询应该是其他的?

时间:2016-09-11 06:04:45

标签: dax

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.

1 个答案:

答案 0 :(得分:0)

它需要动态吗?如果不是你可以做懒惰的方式

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

order by 
sample[col1]