简体   繁体   English

根据 Power BI 中的切片器选择添加或删除视觉对象

[英]Add or delete visuals based on slicer selection in Power BI

How can we add or delete visuals based on slicer selection in power bi?我们如何根据 Power bi 中的切片器选择添加或删除视觉效果? Suppose I have a slicer to select 'State'.假设我有一个切片器来选择“状态”。 Once user selects a state value, the cities of those states should appear as cards with details like population, temperature etc. The cards should correspond to the number of the count of the cities in that state.一旦用户选择了一个州值,这些州的城市应显示为卡片,其中包含人口、温度等详细信息。卡片应与该州的城市数量相对应。 I cannot hide/show the visuals as I need to manually add around 500 such visuals and manually change their properties everytime there is a change.我无法隐藏/显示视觉效果,因为我需要手动添加大约 500 个这样的视觉效果,并在每次发生更改时手动更改它们的属性。

I have a solution that I use but I'd not imagine it being feasible to use for so many different visuals (500 as you say), I use it for 20 and it works great.我有一个我使用的解决方案,但我认为它无法用于这么多不同的视觉效果(如你所说的 500 个),我将它用于 20 个并且效果很好。

You will have to work with the following:您将必须使用以下内容:

  1. A control table一个控制表
  2. A Switch measure that selects the other measures选择其他小节的 Switch 小节
  3. A measure PER city衡量每个城市
  4. A Slicer and bookmarks切片器和书签

Create 1 visual with the population, temperature etc. Then instead of having the source values in there, create a measure per city.使用人口、温度等创建 1 个视觉对象。然后,不要在其中包含源值,而是为每个城市创建一个度量。 After which you can use a Switch True statement to have the values in the visuals change according to the users' selection.之后,您可以使用 Switch True 语句根据用户的选择更改视觉效果中的值。

Basically you then create a control table such as:基本上,您然后创建一个控制表,例如:

   ID     City_Name
    1     London
    2     Paris
    3     New York

After which you then create a new TOP measure: (on top of the others you created per city)之后,您创建一个新的 TOP 度量:(在您为每个城市创建的其他度量之上)

    Selected City= 
Switch(
    SELECTEDVALUE('Control Table'[Number_ID])
    , 1, [London Measure]
    , 2, [Paris Measure]
    , 3, [New York Measure]
    , [Default city without selection]
)

This is the measure that will be added as value to your Visual and will change accordingly.这是将作为价值添加到您的视觉的度量,并将相应地更改。

Once you have your Control Table and measures ready the tedious part starts.一旦您准备好控制表和措施,乏味的部分就开始了。 You use a Chiclet Slicer with the ID Column of your control table as the value.您使用以控制表的 ID 列作为值的 Chiclet Slicer。 Then you create a bookmark per City where only the selected value changes.然后您为每个城市创建一个书签,其中只有选定的值会发生变化。

In this slicer when "1" is selected, save it as bookmark 1 London.在选择“1”时,选择“1”时,将其另存为伦敦书签1。 The control table will ensure the correct measure is used from above Selected City Measure.控制表将确保使用以上选定城市度量的正确度量。

Do this for each city, then hide the slicer in the end.对每个城市都这样做,然后最后隐藏切片器。

Now you will have a single visual that changes according to the users' selection through bookmarks and the selected city calculation (switch statement) without having to create 500 visuals.现在,您将拥有一个根据用户通过书签和所选城市计算(switch 语句)进行的选择而变化的视觉效果,而无需创建 500 个视觉效果。

I suggest you try this first with 3 cities and see if it's a suitable solution.我建议你先在 3 个城市尝试这个,看看它是否是一个合适的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM