我正在尝试构建DAX度量,以基于基础制造商来计算制造商产品的独特功能。
下表列
Manufacturer Product Features
Honda Civic Feature1
Honda Civic Feature2
Honda Civic Feature3
Maruti Ciaz Feature1
Maruti Ciaz Feature4
Maruti Ciaz Feature5
Toyato Camry Feature2
Toyoto Camry Feature4
Toyoto Camry Feature6
Toyoto Camry Feature7
当以“制造商”为每一行创建一个数据透视表时,我想在一个列中显示全部功能,在第二列中显示不同功能。
Manufacturer - TotalCount - DistinctCountOverHonda
Honda - 3 - 3
Maruthi - 3 - 2 ( Feature4, Feature5) are the distinct features, when compared to Honda
Toyoto - 4 - 3 ( Feature4, Feature6, Feature7) are the unique features over Honda.
请帮助我为DistinctCountOverHonda编写度量,并应用过滤器以删除重复项并仅在数据透视表表行中保留制造商的独特功能。
在上面的示例中,我将本田作为与其他制造商进行比较的基础。可能,我将为用户添加切片器,以动态选择基础制造商作为参数表,并根据用户选择进行计数。
答案 0 :(得分:0)
基本上,您希望找到两家制造商的所有独特功能,然后减去本田的独特功能。
DistinctCountOverBase =
VAR CurrentManufacturer =
SELECTEDVALUE ( Table1[Manufacturer] )
VAR CombinedFeatures =
CALCULATETABLE (
DISTINCT ( Table1[Features] ),
Table1[Manufacturer] IN { CurrentManufacturer, "Honda" }
)
VAR HondaFeatures =
CALCULATETABLE ( DISTINCT ( Table1[Features] ), Table1[Manufacturer] = "Honda" )
RETURN
IF (
CurrentManufacturer = "Honda",
COUNTROWS ( HondaFeatures ),
COUNTROWS ( CombinedFeatures ) - COUNTROWS ( HondaFeatures )
)
这是一个较为笼统的解决方案:
DistinctCountOverBase =
VAR Base = "Honda"
VAR CurrentManufacturer =
VALUES ( Table1[Manufacturer] )
VAR CombinedFeatures =
CALCULATETABLE (
DISTINCT ( Table1[Features] ),
FILTER (
ALL ( Table1 ),
Table1[Manufacturer] IN CurrentManufacturer
|| Table1[Manufacturer] = Base
)
)
VAR BaseFeatures =
CALCULATETABLE ( DISTINCT ( Table1[Features] ), Table1[Manufacturer] = Base )
RETURN
IF (
SELECTEDVALUE ( Table1[Manufacturer] ) = Base,
COUNTROWS ( BaseFeatures ),
COUNTROWS ( CombinedFeatures ) - COUNTROWS ( BaseFeatures )
)