0
votes

I know that only CALCULATE can modify the filter context. However following are 2 example using VALUES and ALL.

Example 1:

Revenue = SUMX( Sales, Sales[Order Quantity] * Sales[Unit Price] )

Revenue Avg Order =
AVERAGEX(
    VALUES('Sales Order'[Sales Order]),
    [Revenue]
)

What is the purpose of VALUES in AVERAGEX function? Is this to add an additional filter context?

Example 2:

Product Quantity Rank = RANKX( ALL('Product'[Product]), [Quantity] )

What is the purpose of using ALL in an iterator function?

1

1 Answers

1
votes

Suppose we have a table like this:

ID Sales Order Order Quantity UnitID Unit Price
1 101 10 4 39.99
2 101 15 3 24.99
3 102 5 2 15.99
4 103 5 1 14.99
5 103 10 3 24.99

Since the Sales Order column has duplicates,

Revenue Avg Order = AVERAGEX ( VALUES ( Sales[Sales Order] ), [Revenue] )

gives a different result than

Revenue Avg ID = AVERAGEX ( Sales, [Revenue] )

since the first averages over the three Sales Order values whereas the second averages over the five ID rows.

Table

Using DISTINCT instead of VALUES would work too.


Using ALL is instead of VALUES gives the same total but ignores the local filter context from the table visual:

Revenue Avg All  = AVERAGEX ( ALL ( Sales[Sales Order] ), [Revenue] )

Table2

In this context, ALL is acting as a table function that returns all of the distinct values of the column specified ignoring filter context.