简体   繁体   English

基于切片器选择在 Power BI 中创建动态计算表

[英]Based on slicer selection create dynamic calculated table in Power BI

I'm new to Power BI.我是 Power BI 的新手。 Currently facing similar issue explained below in my product development.目前在我的产品开发中面临下面解释的类似问题。

I have created power bi modle with below dimensions and facts from adventureworksDW.我从 AdventureworksDW 创建了具有以下尺寸和事实的 power bi 模型。

在此处输入图像描述

Then I created a calculated table, which gives result as sum of sales group by ProductSubCategory and ProductCategory.然后我创建了一个计算表,该表将结果作为 ProductSubCategory 和 ProductCategory 的销售组的总和。 Below is the DAX for the calculated table.下面是计算表的 DAX。

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

Now I want to create a new calculated table, which gives me TOPn ProductSubCategory based on the Total sales amount.现在我想创建一个新的计算表,它根据总销售额为我提供 TOPn ProductSubCategory。 Below is the DAX to do this.下面是执行此操作的 DAX。

在此处输入图像描述

and model relationships looks like below.模型关系如下所示。

在此处输入图像描述

I want this TOPn rows to be displayed based on filter condition on product category.我希望根据产品类别的过滤条件显示此 TOPn 行。 Something like below.像下面的东西。

在此处输入图像描述

This works fine when I hardcode the product category value in the DAX itself.当我在 DAX 本身中对产品类别值进行硬编码时,这可以正常工作。 But if I want to change this product category values from the slicer selection, then I didn't get any results.但是,如果我想从切片器选择中更改此产品类别值,那么我没有得到任何结果。

在此处输入图像描述

What you are asking for is not possible as Power BI is currently designed.由于 Power BI 当前是设计的,因此您要求的内容是不可能的。 Slicers cannot affect calculated tables.切片器不能影响计算表。 Calculated columns and calculated tables are evaluated once when the data is first loaded and are static until the data is refreshed.计算列和计算表在首次加载数据时评估一次,并且在刷新数据之前是静态的。

However, you can get the table visual you want in a much simpler manner by writing the appropriate measure and putting that in the table instead of defining an entirely separate table.但是,您可以通过编写适当的度量并将其放入表中而不是定义一个完全独立的表来以更简单的方式获得所需的表视觉效果。

TotalSales = SUM(FactInternetSales[SalesAmount])

The Top N filtering is available in the visual level filters settings.前 N 个过滤在视觉级别过滤器设置中可用。

You can simply use the SELECTEDVALUE function as shown below.您可以简单地使用SELECTEDVALUE函数,如下所示。

var __SelectedValue = SELECTEDVALUE('ProductSales'[EnglishProductCatogaryName])
return
Filter(
    'ProductSales',
    'ProductSales'[EnglishProductCatogaryName] = __SelectedValue 
    )
)

thanks for the reply. 谢谢回复。

As you suggested, I know that I can get TopN Product Sub Category values by creating appropriate measures and without creating entirely separate calculated table. 如您所建议,我知道我可以通过创建适当的度量而无需创建完全独立的计算表来获得TopN产品子类别值。

enter image description here 在此处输入图片说明

enter image description here 在此处输入图片说明

And it is possible to get only TopN results by creating a visual filter. 通过创建视觉过滤器,可能仅获得TopN结果。

enter image description here 在此处输入图片说明

enter image description here 在此处输入图片说明

Issue is resolved. 问题已解决。 :) . :)

But my requirement is different. 但是我的要求是不同的。 Based on the top 3 Product Sub Categories from the above result, I want to create 3 different visuals/charts in the report dynamically. 基于以上结果中的前3个产品子类别,我想在报告中动态创建3种不同的视觉效果/图表。 Something like below. 像下面这样。

enter image description here 在此处输入图片说明

Here I have applied visual filter manually for 3 different charts. 在这里,我为3个不同的图表手动应用了可视过滤器。

enter image description here 在此处输入图片说明

I want this visual filter to be applied dynamically. 我希望此视觉过滤器可以动态应用。 That is when I select “Bikes” Product Category from the slicer then these 3 charts visual filter to be dynamically applied for top 3 Product Sub Categories of “Bikes”. 那就是当我从切片器中选择“自行车”产品类别时,然后将这3个图表可视过滤器动态应用于“自行车”的前3个产品子类别。 Now, when I select “Bikes” Product Category from the slicer, these 3 charts will show results like below. 现在,当我从切片器中选择“自行车”产品类别时,这3个图表将显示如下结果。 :( . :(。

enter image description here 在此处输入图片说明

To achieve this requirement, I thought dynamic calculated table will help me, which will give always give top 3 Product Sub Categories based on my Product Category slicer selection. 为了达到此要求,我认为动态计算表将对我有所帮助,该表将根据我的“产品类别”切片器选择始终给出前3名“产品子类别”。

Hope, now my requirement is clear!! 希望,现在我的要求很明确了!!

Please suggest if there is any workaround or alternate approach to get result for my requirement. 请提出是否有任何解决方法或替代方法来获得符合我要求的结果。

Thanks in advance. 提前致谢。

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

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