Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
977 views
in Technique[技术] by (71.8m points)

powerbi - How does ALL (tablename/columnname) work when used as 2nd parameter of CALCULATE?

The model has sales fact and product dimension. There is M:1 relationship on product_id column.

Assume there is a table visual with 2 columns: Product name and a measure.

Following are 2 sub-questions -

  1. Question regarding measure 1:

Measure 1 =

CALCULATE(

????????COUNT(Sales[SalesId]),

????????ALL('Product')

????)

Does ALL remove the filter from the product table from the sales table or does ALL return the unfiltered product table that leads to clearing of the filter context? Since table expansion happens only towards the 1 side, then how does un-filtering on product affect the sales calculation? Just trying to visualize the underlying logic of how the un-filtering works.

  1. Question regarding Measure2: Code:

    Measure2 = CALCULATE(

    ????????COUNT(Sales[SalesId]),

    ????????ALL('Product'[ProductName])

    ????)

ALL returns a single column (ProductName) table with all filters removed and there is no table expansion happening here so how does it logically work? Again I'm trying to visualize the underlying logic of how the un-filtering works.

question from:https://stackoverflow.com/questions/65862935/how-does-all-tablename-columnname-work-when-used-as-2nd-parameter-of-calculate

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

ALL used as a filter argument is filter modifier. It removes the filter on its argument.

When the argument is a table, it removes the filter over the entire expanded table (the table specified as argument). Whent the argument is one or more columns, it removes the filters over the specified columns.

Filter removals happen during the fourth step in the CALCULATE execution, after the context transition and before the expression evaluation

The explanation of the CALCULATE execution step can be found in the DAX Guide

In the Measure 1, all filters are removed from the 'Product' table. In the Measure 2, only the filter existing over 'Product'[Name] is removed

In recent DAX verisions, when used as a filter modifier, ALL can be replaced by REMOVEFILTERS


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...