cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
db2907
Helper II
Helper II

How the Filter definition of the metric can affect the final result.

Let's assume that I have the Products table in my model defined like this:

 

ProductIDUnitPriceUnitsInStockDiscontinued
11050TRUE
21530FALSE
32020TRUE
42510TRUE
5515FALSE

 

I have created two metrics :

 

Value1  = 

CALCULATE ( SUMX ( Products, Products[UnitPrice] * Products[UnitsInStock] ), FILTER ( Products, Products[Discontinued] = TRUE ) )

 

Value2 = 

CALCULATE ( SUMX ( Products, Products[UnitPrice] * Products[UnitsInStock] ), Products[Discontinued] = TRUE )

 

db2907_0-1686071686137.png

 

 

The only difference is the definition of the filter. I have evaluated the results in Power Desktop but I do not see any difference. This leads to my question: How could this definition affect the final result of the metric or when might this occur?

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

The two measures are essentially identical, both are calculating the result for products which are discontinued. 

The definition for value2 is rewritten internally to be

Value2 =
CALCULATE (
    SUMX ( Products, Products[UnitPrice] * Products[UnitsInStock] ),
    FILTER ( ALL ( Products[Discontinued] ), Products[Discontinued] = TRUE )
)

The form of CALCULATE where you can specify a predicate as a filter rather than a table is merely syntax sugar, to make the code easier to read and write.

 

View solution in original post

1 REPLY 1
johnt75
Super User
Super User

The two measures are essentially identical, both are calculating the result for products which are discontinued. 

The definition for value2 is rewritten internally to be

Value2 =
CALCULATE (
    SUMX ( Products, Products[UnitPrice] * Products[UnitsInStock] ),
    FILTER ( ALL ( Products[Discontinued] ), Products[Discontinued] = TRUE )
)

The form of CALCULATE where you can specify a predicate as a filter rather than a table is merely syntax sugar, to make the code easier to read and write.

 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors