在 DAX 度量中识别上下文过滤器
Identifying Context Filter in DAX Measure
如何在 Power Pivot 中创建一个 DAX 度量值来显示用作 Pivot 中每一行的最低级别筛选器上下文的列名称Table?
我有 2 个 table 与帐户列相关。
TableDimAccount
Account,Model_L1,Model_L2,Model_L3,Business_L1,Business_L2,Business_L3
1,Working Capital,Trade Payables,Trade Creditors,Opex,Technology,Managed Services
2,Investing,Capex Creditors and Accruals,Capex Trade Creditors,Capex,Capex Creditors,Intangible Asset Creditors
3,Working Capital,Trade Receivables,Prepaid Debtors,Receivables,Prepaid Receipts,Prepaid MBB Receipts
Table BalSheet
Account,Value
1,50
2,60
3,40
用于计算上下文过滤器的 DAX 度量
MEASURE BalSheet[CurrentLevel]
=SWITCH(TRUE(),
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L3])),
ALLEXCEPT(DimAccount, DimAccount[Model_L3])) = 1,
"Model_L3",
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L2])),
ALLEXCEPT(DimAccount, DimAccount[Model_L2])) = 1,
"Model_L2",
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L1])),
ALLEXCEPT(DimAccount, DimAccount[Model_L1])) = 1,
"Model_L1",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L3])),
ALLEXCEPT(DimAccount, DimAccount[Business_L3])) = 1,
"Business_L3",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L2])),
ALLEXCEPT(DimAccount, DimAccount[Business_L2])) = 1,
"Business_L2",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L1])),
ALLEXCEPT(DimAccount, DimAccount[Business_L1])) = 1,
"Business_L1",
"All"
)
具有单一层次结构的结果
该措施适用于单一层次结构。这是枢轴 table 的样子(在 csv 中)。
Model_L1,Model_L2,Model_L3,CurrentLevel
Investing,Capex Creditors and Accruals,Capex Trade Creditors,Model_L3
Investing,Capex Creditors and Accruals,,Model_L2
Investing,,,Model_L1
Working Capital,Trade Payables,Trade Creditors,Model_L3
Working Capital,Trade Payables,,Model_L2
Working Capital,Trade Receivables,Prepaid Debtors,Model_L3
Working Capital,Trade Receivables,,Model_L2
Working Capital,,,Model_L1
Grand Total,,,All
具有混合层次结构的结果
当我将 2 个层次结构混合在一起(例如,模型和业务)时,该度量在应该显示 "Business_L2" 或 "Business_L3" 时一直显示 "Model_L1"。这是枢轴 table 的样子(在 csv 中)。
Model_L1,Business_L2,Business_L3,CurrentLevel
Investing,Capex Creditors,Intangible Asset Creditors,Model_L1
Investing,Capex Creditors Total,,Model_L1
Investing,,,Model_L1
Working Capital,Prepaid Receipts,Prepaid MBB Receipts,Model_L1
Working Capital,Prepaid Receipts Total,,Model_L1
Working Capital,Technology,Managed Services,Model_L1
Working Capital,Technology Total,,Model_L1
Working Capital,,,Model_L1
Grand Total,,,All
这就是我希望枢轴 table 看起来像的样子:
Model_L1,Business_L2,Business_L3,CurrentLevel
Investing,Capex Creditors,Intangible Asset Creditors,Business_L3
Investing,Capex Creditors Total,,Business_L2
Investing,,,Model_L1
Working Capital,Prepaid Receipts,Prepaid MBB Receipts,Business_L3
Working Capital,Prepaid Receipts Total,,Business_L2
Working Capital,Technology,Managed Services,Business_L3
Working Capital,Technology Total,,Business_L2
Working Capital,,,Model_L1
Grand Total,,,All
当您将 "Model_L1"、"Business_L2"、"Business_3" 作为基准 table 行时,[CurrentLevel] 度量总是计算为 "Model_L1" 的原因fields 是因为 "Model_L1" 在 SWITCH() 语句中位于 "Business_X" 之上。这应该会给你想要的结果:
=SWITCH(TRUE(),
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L3])),
ALLEXCEPT(DimAccount, DimAccount[Model_L3])) = 1,
"Model_L3",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L3])),
ALLEXCEPT(DimAccount, DimAccount[Business_L3])) = 1,
"Business_L3",
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L2])),
ALLEXCEPT(DimAccount, DimAccount[Model_L2])) = 1,
"Model_L2",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L2])),
ALLEXCEPT(DimAccount, DimAccount[Business_L2])) = 1,
"Business_L2",
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L1])),
ALLEXCEPT(DimAccount, DimAccount[Model_L1])) = 1,
"Model_L1",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L1])),
ALLEXCEPT(DimAccount, DimAccount[Business_L1])) = 1,
"Business_L1",
"All"
)
如何在 Power Pivot 中创建一个 DAX 度量值来显示用作 Pivot 中每一行的最低级别筛选器上下文的列名称Table?
我有 2 个 table 与帐户列相关。
TableDimAccount
Account,Model_L1,Model_L2,Model_L3,Business_L1,Business_L2,Business_L3
1,Working Capital,Trade Payables,Trade Creditors,Opex,Technology,Managed Services
2,Investing,Capex Creditors and Accruals,Capex Trade Creditors,Capex,Capex Creditors,Intangible Asset Creditors
3,Working Capital,Trade Receivables,Prepaid Debtors,Receivables,Prepaid Receipts,Prepaid MBB Receipts
Table BalSheet
Account,Value
1,50
2,60
3,40
用于计算上下文过滤器的 DAX 度量
MEASURE BalSheet[CurrentLevel]
=SWITCH(TRUE(),
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L3])),
ALLEXCEPT(DimAccount, DimAccount[Model_L3])) = 1,
"Model_L3",
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L2])),
ALLEXCEPT(DimAccount, DimAccount[Model_L2])) = 1,
"Model_L2",
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L1])),
ALLEXCEPT(DimAccount, DimAccount[Model_L1])) = 1,
"Model_L1",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L3])),
ALLEXCEPT(DimAccount, DimAccount[Business_L3])) = 1,
"Business_L3",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L2])),
ALLEXCEPT(DimAccount, DimAccount[Business_L2])) = 1,
"Business_L2",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L1])),
ALLEXCEPT(DimAccount, DimAccount[Business_L1])) = 1,
"Business_L1",
"All"
)
具有单一层次结构的结果
该措施适用于单一层次结构。这是枢轴 table 的样子(在 csv 中)。
Model_L1,Model_L2,Model_L3,CurrentLevel
Investing,Capex Creditors and Accruals,Capex Trade Creditors,Model_L3
Investing,Capex Creditors and Accruals,,Model_L2
Investing,,,Model_L1
Working Capital,Trade Payables,Trade Creditors,Model_L3
Working Capital,Trade Payables,,Model_L2
Working Capital,Trade Receivables,Prepaid Debtors,Model_L3
Working Capital,Trade Receivables,,Model_L2
Working Capital,,,Model_L1
Grand Total,,,All
具有混合层次结构的结果
当我将 2 个层次结构混合在一起(例如,模型和业务)时,该度量在应该显示 "Business_L2" 或 "Business_L3" 时一直显示 "Model_L1"。这是枢轴 table 的样子(在 csv 中)。
Model_L1,Business_L2,Business_L3,CurrentLevel
Investing,Capex Creditors,Intangible Asset Creditors,Model_L1
Investing,Capex Creditors Total,,Model_L1
Investing,,,Model_L1
Working Capital,Prepaid Receipts,Prepaid MBB Receipts,Model_L1
Working Capital,Prepaid Receipts Total,,Model_L1
Working Capital,Technology,Managed Services,Model_L1
Working Capital,Technology Total,,Model_L1
Working Capital,,,Model_L1
Grand Total,,,All
这就是我希望枢轴 table 看起来像的样子:
Model_L1,Business_L2,Business_L3,CurrentLevel
Investing,Capex Creditors,Intangible Asset Creditors,Business_L3
Investing,Capex Creditors Total,,Business_L2
Investing,,,Model_L1
Working Capital,Prepaid Receipts,Prepaid MBB Receipts,Business_L3
Working Capital,Prepaid Receipts Total,,Business_L2
Working Capital,Technology,Managed Services,Business_L3
Working Capital,Technology Total,,Business_L2
Working Capital,,,Model_L1
Grand Total,,,All
当您将 "Model_L1"、"Business_L2"、"Business_3" 作为基准 table 行时,[CurrentLevel] 度量总是计算为 "Model_L1" 的原因fields 是因为 "Model_L1" 在 SWITCH() 语句中位于 "Business_X" 之上。这应该会给你想要的结果:
=SWITCH(TRUE(),
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L3])),
ALLEXCEPT(DimAccount, DimAccount[Model_L3])) = 1,
"Model_L3",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L3])),
ALLEXCEPT(DimAccount, DimAccount[Business_L3])) = 1,
"Business_L3",
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L2])),
ALLEXCEPT(DimAccount, DimAccount[Model_L2])) = 1,
"Model_L2",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L2])),
ALLEXCEPT(DimAccount, DimAccount[Business_L2])) = 1,
"Business_L2",
CALCULATE(COUNTROWS(VALUES(DimAccount[Model_L1])),
ALLEXCEPT(DimAccount, DimAccount[Model_L1])) = 1,
"Model_L1",
CALCULATE(COUNTROWS(VALUES(DimAccount[Business_L1])),
ALLEXCEPT(DimAccount, DimAccount[Business_L1])) = 1,
"Business_L1",
"All"
)