DAX HASONEVALUE 行过滤器
DAX HASONEVALUE row filter
12 Total :=
SWITCH (
TRUE (),
HASONEVALUE ([level04] ), CALCULATE (
[Local],
DATESINPERIOD (
Calendar[Date],
MAX ( Calendar[Date] ),
-12,
MONTH
)
),
HASONEVALUE ([level03]),If([level 03]= "calculation:" && [level03]= "Cash:" && [level03]= "Costs:"=>0, Blank(), CALCULATE (
[Local],
DATESINPERIOD (
Calendar[Date],
MAX ( Calendar[Date] ),
-12,
MONTH
)
)
),
HASONEVALUE ( [level02] ), BLANK ()
)
我想添加条件,如果杠杆 03 = 现金、计算和成本,则 return 留空以删除小计行。我试过类似的东西,但它不能正常工作,它给我错误 "value for column level03 cannot be determined in the current context"。如何在 level03 列中添加该条件?
附带说明一下,"its not working properly" 对确定问题的根源毫无帮助。特别是在 Power Pivot/Tabular 模型中,this link provides a list of ways to help answerers help you。
语法上有一些错误。让我们解决这些问题,看看这种行为是否合适,然后再深入研究替代度量定义。
这一段的问题是:
...
,HASONEVALUE([level03])
// Note, you are inconsistent in referring to [level03] and
// [level 03]
,If( // Below you are testing column references against scalar
// literals. DAX doesn't understand how to do this, so you
// have to wrap each reference in a VALUES() function, which
// can be implicitly converted to a scalar value
[level 03] = 'calculation:' // DAX needs double quotes: ""
&& [level03]= 'Cash:' // You have multiple predicates
&& [level03]=' Costs:'=>0 // for a single field combined
// with a logical and - these
// can't all simultaneously be true
,Blank()
,CALCULATE(
[Local]
,DATESINPERIOD(
Calendar[Date],
MAX ( Calendar[Date] ),
-12,
MONTH
)
)
)
,....
我将在我的重写中将谓词组合更改为逻辑或,以便此 IF() 可以 return 为空白。上面这样写,即使修复了语法错误也会导致它总是计算else条件,因为[level 03]不能同时具有"calculation:"、"Cash:"和" Costs:=> 0".
...
,HASONEVALUE('<table>'[level03])
// As a best practice, you should always use fully qualified
// column references - 'table'[field]
// Also, I've referred only to [level03] below
,IF( // Note we've wrapped [level 03] in VALUES() below - this will
// allow our comparisons to scalar literals
VALUES('<table>'[level03]) = "calculation:" // double quotes
|| VALUES('<table>'[level03]) = "Cash:"
// Note: we've changed the logical and, &&, to a logical
// or, || - meaning if any 1 of these predicates is true,
// we'll return BLANK
|| VALUES('<table>'[level03]) = " Costs:=>0"
,BLANK()
,CALCULATE(
[Local]
,DATESINPERIOD(
Calendar[Date]
,MAX( Calendar[Date] )
,-12
,MONTH
)
)
)
,....
这将检查枢轴 table 上的任何单元格,其中 [level03] 恰好有一个不同的值 - 如果为真,它将计算 IF() 函数。
IF() 函数将检查 [level03] 的值。如果该值是以下三个值中的任何一个,"calculation:"、"Cash:" 或“成本:=>0”,它将 return 空白。如果 [level03] 的值不是这三个中的任何一个,它将评估 CALCULATE(),return 是滚动 12 个月期间的 [本地] 度量。
12 Total :=
SWITCH (
TRUE (),
HASONEVALUE ([level04] ), CALCULATE (
[Local],
DATESINPERIOD (
Calendar[Date],
MAX ( Calendar[Date] ),
-12,
MONTH
)
),
HASONEVALUE ([level03]),If([level 03]= "calculation:" && [level03]= "Cash:" && [level03]= "Costs:"=>0, Blank(), CALCULATE (
[Local],
DATESINPERIOD (
Calendar[Date],
MAX ( Calendar[Date] ),
-12,
MONTH
)
)
),
HASONEVALUE ( [level02] ), BLANK ()
)
我想添加条件,如果杠杆 03 = 现金、计算和成本,则 return 留空以删除小计行。我试过类似的东西,但它不能正常工作,它给我错误 "value for column level03 cannot be determined in the current context"。如何在 level03 列中添加该条件?
附带说明一下,"its not working properly" 对确定问题的根源毫无帮助。特别是在 Power Pivot/Tabular 模型中,this link provides a list of ways to help answerers help you。
语法上有一些错误。让我们解决这些问题,看看这种行为是否合适,然后再深入研究替代度量定义。
这一段的问题是:
...
,HASONEVALUE([level03])
// Note, you are inconsistent in referring to [level03] and
// [level 03]
,If( // Below you are testing column references against scalar
// literals. DAX doesn't understand how to do this, so you
// have to wrap each reference in a VALUES() function, which
// can be implicitly converted to a scalar value
[level 03] = 'calculation:' // DAX needs double quotes: ""
&& [level03]= 'Cash:' // You have multiple predicates
&& [level03]=' Costs:'=>0 // for a single field combined
// with a logical and - these
// can't all simultaneously be true
,Blank()
,CALCULATE(
[Local]
,DATESINPERIOD(
Calendar[Date],
MAX ( Calendar[Date] ),
-12,
MONTH
)
)
)
,....
我将在我的重写中将谓词组合更改为逻辑或,以便此 IF() 可以 return 为空白。上面这样写,即使修复了语法错误也会导致它总是计算else条件,因为[level 03]不能同时具有"calculation:"、"Cash:"和" Costs:=> 0".
...
,HASONEVALUE('<table>'[level03])
// As a best practice, you should always use fully qualified
// column references - 'table'[field]
// Also, I've referred only to [level03] below
,IF( // Note we've wrapped [level 03] in VALUES() below - this will
// allow our comparisons to scalar literals
VALUES('<table>'[level03]) = "calculation:" // double quotes
|| VALUES('<table>'[level03]) = "Cash:"
// Note: we've changed the logical and, &&, to a logical
// or, || - meaning if any 1 of these predicates is true,
// we'll return BLANK
|| VALUES('<table>'[level03]) = " Costs:=>0"
,BLANK()
,CALCULATE(
[Local]
,DATESINPERIOD(
Calendar[Date]
,MAX( Calendar[Date] )
,-12
,MONTH
)
)
)
,....
这将检查枢轴 table 上的任何单元格,其中 [level03] 恰好有一个不同的值 - 如果为真,它将计算 IF() 函数。
IF() 函数将检查 [level03] 的值。如果该值是以下三个值中的任何一个,"calculation:"、"Cash:" 或“成本:=>0”,它将 return 空白。如果 [level03] 的值不是这三个中的任何一个,它将评估 CALCULATE(),return 是滚动 12 个月期间的 [本地] 度量。