Is it possible to use a slicer as a parameter to a DAX Summarize function?

谁说胖子不能爱 提交于 2019-12-24 06:44:14

问题


I have a FactLosses Table, and a DimAccumulation table. I have brought them into PowerBi and I have placed a slicer to choose which accumulation zones i am interested in.

Once the user has selected the zones, i want to perform a group by year on the losses and sum the losses into year buckets. But only on the data that applies to the zones the user picked.

I am using the following DAX code to do the group by like so...

Table = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))

The problem is the new table always produces the same result. i.e When i make changes to which accumulation perils should be included it makes no difference to the summation. (it is summing the entire table)

I'd like to use the slicer to filter the fact table and then have the DAX query run on the filtered list. Is this possible?


回答1:


If you want these tables to be responsive to filters or slicers on your report, then you can't write these as calculated tables that show up under the Data tab since those are computed before any filtering happens.

To get what you want, you have to do everything inside of a measure, since those are what respond to slicers. If you're looking for the max loss year once the grouping and summing are completed, you can write a measure along these lines:

Year Max =
    VAR CalculatedTable = SUMMARIZECOLUMNS(FactForwardLookingAccumulation[Year], "Losses By Year", SUM(FactForwardLookingAccumulation[Net Loss Our Share Usd]))
    RETURN MAXX(CalculatedTable, [Losses By Year])

Writing it this way will allow the calculated table to respond to your slicers and filters.



来源:https://stackoverflow.com/questions/49015485/is-it-possible-to-use-a-slicer-as-a-parameter-to-a-dax-summarize-function

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