不同表的DAX累计总和比较
DAX Cumulative Total Comparison from Different Tables
如何创建一个 DAX 度量来显示收据余额大于或等于付款余额的第一个收据日期?
例如,对于 Jun,我希望 [Payment Receipt Date Avg] 度量值显示为 Jan,因为 Receipt Balance 为 10,大于 Payment Balance 8。
对于 8 月,它将显示为 2 月,因为这是收款余额至少为 13 的付款余额的第一个日期。
想要的结果:
数据模型
Table: Po 收据
Table:付款
尝试的解决方案
我已经定义了以下措施:
Receipt Balance:
=CALCULATE
(
SUM(PoReceipt[Quantity Received]),
FILTER
(
ALL ( PaymentDates ),
PaymentDates[Payment_FullDate] <= MAX ( PaymentDates[Payment_FullDate] )
)
)
Payment Balance:
=CALCULATE
(
SUM(Payment[Payment Amount]),
FILTER
(
ALL ( PaymentDates ),
PaymentDates[Payment_FullDate] <= MAX ( PaymentDates[Payment_FullDate] )
)
)
创建计算列以获得第一个日期,该日期的净收入 运行 总额(即收入减去付款 运行 总额)大于当前行上下文中的付款金额。计算列将需要执行以下操作:
- Return 每个 [PO 编号] 的 运行 总 [付款金额]。使用 EARLIER 函数,以便对于外部上下文中的每一行,您可以对内部上下文中的所有行求和,其中内部行的 [Payment Date] 小于或等于外部行,并且内部行的 [Po Num]等于外排。
- Return 基于 PoReceipt table 的摘要 table,其中有一个扩展栏 "Receipt Balance Calc"。扩展列计算 PoReceipt[Quantity Received] 的 运行 总数,类似于步骤 1。摘要 table 按列 [Po Num] 和 [Receipt Date] 分组以避免执行相同的计算不止一次(因为 [Receipt Num] 列导致多行具有相同的 [Po Num])。
- 过滤结果以仅包含收款余额大于或等于付款余额的行。
查看计算列的 DAX 代码:
Payment[Payment Balance Calc]
=CALCULATE (
SUM ( Payment[Payment Amount] ),
FILTER (
Payment,
Payment[Payment Date] <= EARLIER ( Payment[Payment Date] )
&& Payment[Po Num] = EARLIER ( Payment[Po Num] )
)
)
Payment[Payment Receipt Date]
=CALCULATE (
MIN ( PoReceipt[Receipt Date] ),
ALL ( PaymentDates ),
FILTER (
ADDCOLUMNS (
SUMMARIZE (
PoReceipt,
PoReceipt[Po Num],
PoReceipt[Receipt Date]
),
"Receipt Balance Calc",
CALCULATE (
SUM ( PoReceipt[Quantity Received] ),
FILTER (
PoReceipt,
PoReceipt[Receipt Date] <= EARLIER ( PoReceipt[Receipt Date] )
&& PoReceipt[Po Num] = EARLIER ( PoReceipt[Po Num] )
)
)
),
[Receipt Balance Calc] >= EARLIER ( Payment[Payment Balance Calc] )
)
)
最后,创建以下度量来计算收货日期的加权平均值:
Payment Receipt Date Avg:=
SUMX (
Payment,
Payment[Payment Amount] * Payment[Payment Receipt Date]
/ SUM ( Payment[Payment Amount] )
)
如何创建一个 DAX 度量来显示收据余额大于或等于付款余额的第一个收据日期?
例如,对于 Jun,我希望 [Payment Receipt Date Avg] 度量值显示为 Jan,因为 Receipt Balance 为 10,大于 Payment Balance 8。
对于 8 月,它将显示为 2 月,因为这是收款余额至少为 13 的付款余额的第一个日期。
想要的结果:
数据模型
Table: Po 收据
Table:付款
尝试的解决方案
我已经定义了以下措施:
Receipt Balance:
=CALCULATE
(
SUM(PoReceipt[Quantity Received]),
FILTER
(
ALL ( PaymentDates ),
PaymentDates[Payment_FullDate] <= MAX ( PaymentDates[Payment_FullDate] )
)
)
Payment Balance:
=CALCULATE
(
SUM(Payment[Payment Amount]),
FILTER
(
ALL ( PaymentDates ),
PaymentDates[Payment_FullDate] <= MAX ( PaymentDates[Payment_FullDate] )
)
)
创建计算列以获得第一个日期,该日期的净收入 运行 总额(即收入减去付款 运行 总额)大于当前行上下文中的付款金额。计算列将需要执行以下操作:
- Return 每个 [PO 编号] 的 运行 总 [付款金额]。使用 EARLIER 函数,以便对于外部上下文中的每一行,您可以对内部上下文中的所有行求和,其中内部行的 [Payment Date] 小于或等于外部行,并且内部行的 [Po Num]等于外排。
- Return 基于 PoReceipt table 的摘要 table,其中有一个扩展栏 "Receipt Balance Calc"。扩展列计算 PoReceipt[Quantity Received] 的 运行 总数,类似于步骤 1。摘要 table 按列 [Po Num] 和 [Receipt Date] 分组以避免执行相同的计算不止一次(因为 [Receipt Num] 列导致多行具有相同的 [Po Num])。
- 过滤结果以仅包含收款余额大于或等于付款余额的行。
查看计算列的 DAX 代码:
Payment[Payment Balance Calc]
=CALCULATE (
SUM ( Payment[Payment Amount] ),
FILTER (
Payment,
Payment[Payment Date] <= EARLIER ( Payment[Payment Date] )
&& Payment[Po Num] = EARLIER ( Payment[Po Num] )
)
)
Payment[Payment Receipt Date]
=CALCULATE (
MIN ( PoReceipt[Receipt Date] ),
ALL ( PaymentDates ),
FILTER (
ADDCOLUMNS (
SUMMARIZE (
PoReceipt,
PoReceipt[Po Num],
PoReceipt[Receipt Date]
),
"Receipt Balance Calc",
CALCULATE (
SUM ( PoReceipt[Quantity Received] ),
FILTER (
PoReceipt,
PoReceipt[Receipt Date] <= EARLIER ( PoReceipt[Receipt Date] )
&& PoReceipt[Po Num] = EARLIER ( PoReceipt[Po Num] )
)
)
),
[Receipt Balance Calc] >= EARLIER ( Payment[Payment Balance Calc] )
)
)
最后,创建以下度量来计算收货日期的加权平均值:
Payment Receipt Date Avg:=
SUMX (
Payment,
Payment[Payment Amount] * Payment[Payment Receipt Date]
/ SUM ( Payment[Payment Amount] )
)