【发布时间】:2023-03-05 02:19:01
【问题描述】:
我对 Power BI 中的行上下文和筛选上下文的可迭代和不可迭代筛选器进行了实验。
我的理解是度量有过滤上下文,而计算列有行上下文
这是衡量的 Dax:
UnitPrice (Sum) =
SUM(
'Sales by Store'[unit_price]
)
UnitPrice (Sumx) =
SUMX(
'Sales by Store',
'Sales by Store'[unit_price]
)
UnitPrice (CalSum) =
CALCULATE(
SUM(
'Sales by Store'[unit_price]
)
)
UnitPrice (CalSumx) =
CALCULATE(
SUMX(
'Sales by Store',
'Sales by Store'[unit_price]
)
)
矩阵表中的输出是显示同一产品类别(整豆/茶)中每种产品各自的单价:
这意味着度量具有过滤器上下文,但是为什么我们 Sum 和 Calculate Sum 不会为每个产品显示相同数量的产品组的总单价,因为这两个 Dax 函数都不可迭代?
对于计算列,我在 Power Query 中使用另一个名为 Quantity Sold 的列。
Qty Sold_1 (Sum) =
SUM(
'Sales by Store',
'Sales by Store'[quantity_sold]
)
Qty Sold_2 (Sumx) =
SUMX(
'Sales by Store',
'Sales by Store'[quantity_sold]
)
Qty Sold_3 (CalSum) =
CALCULATE(
SUM(
'Sales by Store'[quantity_sold]
)
)
Qty Sold_4 (CalSumx) =
CALCULATE(
SUMX(
'Sales by Store',
'Sales by Store'[quantity_sold]
)
)
输出为 Sum,Sumx 将显示所有行的总金额,而 Calculate Sum 和 Calculate Sumx 将显示各自的单价。 售出的数量是原始列。
| Transaction ID | quantity sold | Qty Sold_1 (Sum) | Qty Sold_2 (Sumx) | Qty Sold_3 (CalSum) | Qty Sold_4 (CalSumX) |
|---|---|---|---|---|---|
| 131 | 1 | 6 | 6 | 1 | 1 |
| 192 | 2 | 6 | 6 | 1 | 1 |
| 460 | 3 | 6 | 6 | 1 | 1 |
为什么 Sumx(能够逐行迭代)没有显示行上下文中的相应销售量,并且计算 Sum 没有显示所有行的总销售量,因为它不能在行上下文中逐行迭代?
【问题讨论】:
标签: dax powerquery powerbi-desktop