PowerBI: Slicer to filter a table Only when more than 1 value is selected

折月煮酒 提交于 2019-12-11 08:03:47

问题


I have a table with 5 categories and units displayed into 2 types, Actual and budget.

I want to filter this table. Only when 2 or more values are selected in the slicer. Something like this.

I though of adding a measure, but dont know how to work the if statement exactly.

Measure = IF(COUNTROWS(ALLSELECTED(Report[Shipment Group])) = 1, "Something which would not filter the units", SELECTEDVALUE(Report[Units], SUM(Report[Units])))

Not sure if this is correct approach.Would like to know if any other approach is possible. Any help would be helpful. Thank you in advance.


回答1:


This is a bit of an odd request, but I think I have something that works.

  1. First, you need to create a separate table for your slicer values (or else you can't control filtering how you want). You can hit the new table button and define it as follows:

Groups = VALUES(Report[Shipment Group])

  1. Set your slicer to use Groups[Shipment Group] instead of Report[Shipment Group].

  2. Define your new measure as follows:


Measure = IF(COUNTROWS(ALLSELECTED(Groups[Shipment Group])) = 1,
             SUM(Report[Units]),
             SUMX(FILTER(Report,
                         Report[Shipment Group] IN VALUES(Groups[Shipment Group])),
                  Report[Units]))

or equivalently

Measure = IF(COUNTROWS(ALLSELECTED(Groups[Shipment Group])) = 1,
             SUM(Report[Units]),
             CALCULATE(SUM(Report[Units]),
                       FILTER(Report,
                              Report[Shipment Group] IN VALUES(Groups[Shipment Group]))))

Note: Double check that Power BI has not automatically created a relationship between the Groups and Report tables. You don't want that.



来源:https://stackoverflow.com/questions/47781009/powerbi-slicer-to-filter-a-table-only-when-more-than-1-value-is-selected

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