HASONEVALUE 和 HASONEFILTER 都是用來檢查篩選狀態(tài)的函數(shù)扣溺。
- HASONEVALUE 在參數(shù)列在當前篩選上下文中只有一個可見值時, 返回TRUE, 否則FALSE锥余。
- HASONEFILTER 在參數(shù)列被直接篩選(direct-filter)并且只篩選一個值時痢掠,返回TRUE, 否則FALSE
它們有相似的語法嘲恍,都只接受基列(存在于模型中的列)作為參數(shù)雄驹。
?然而, 它們有一個顯著的區(qū)別:
- HASONEVALUE 基于交叉篩選(cross-filter)工作医舆。
- HASONEFILTER 基于直接篩選(direct-filter)工作。
?我們通過2個示例,演示這一區(qū)別攻冷。
- 在參數(shù)列被直接篩選一個值時, 此時,HASONEFILTER 返回TRUE, 然而可能因為篩選的值在篩選上下文中不可見里烦,HASONEVALUE 返回FALSE禁谦。
-- 一個列可能被直接篩選了一個值, 但是因為交叉篩選沒有可見值。
DEFINE
MEASURE Sales[Has One Filter] =
CALCULATE (
HASONEFILTER ( 'Product'[Category] ),
'Product'[Category] = "Home Appliances",
'Product'[Product Name] = "Contoso 512MB MP3 Player E51 Silver"
)
MEASURE Sales[Has One Value] =
CALCULATE (
HASONEVALUE ( 'Product'[Category] ),
'Product'[Category] = "Home Appliances",
'Product'[Product Name] = "Contoso 512MB MP3 Player E51 Silver"
)
MEASURE Sales[Are there any products?] =
CALCULATE (
COUNTROWS ( 'Product' ) > 0,
'Product'[Category] = "Home Appliances",
'Product'[Product Name] = "Contoso 512MB MP3 Player E51 Silver"
)
EVALUATE
{
( "Has One Filter", [Has One Filter] ),
( "Has One Value", [Has One Value] ),
( "Are there any products?", [Are there any products?] )
}
- 一個列可能由于交叉篩選只有一個可見值,此時遥皂,HASONEVALUE 返回TRUE, 然而由于列沒有被直接篩選, HASONEFILTER 返回FALSE。
-- 一個列可能由于交叉篩選只有一個可見值, 但并沒被直接篩選弟孟。
DEFINE
MEASURE Sales[Has One Filter] =
CALCULATE (
HASONEFILTER ( 'Product'[Category] ),
'Product'[Product Name] = "Contoso 512MB MP3 Player E51 Silver"
)
MEASURE Sales[Has One Value] =
CALCULATE (
HASONEVALUE ( 'Product'[Category] ),
'Product'[Product Name] = "Contoso 512MB MP3 Player E51 Silver"
)
EVALUATE
{
( "Has One Filter", [Has One Filter] ),
( "Has One Value", [Has One Value] )
}
image.png