В Power BI вы можете сделать это в Power Query:
let
Source = SourceTable,
fnDistinct = (MyTable, MyServiceid) =>
let
#"Filtered Rows" = Table.SelectRows(MyTable, each ([Serviceid] = MyServiceid)),
#"Distinct Products" = List.Count(List.Distinct(#"Filtered Rows"[Product]))
in
#"Distinct Products",
#"Added M Type" = Table.AddColumn(Source, "M Type", each if fnDistinct(Source, [Serviceid]) > 1 then "Multiple Products" else "Single Product", type text)
in
#"Added M Type"
Или используя DAX:
DAX Type =
VAR CountProducts =
CALCULATE(
DISTINCTCOUNT ( Table1[Product] ),
ALLEXCEPT ( Table1, Table1[Serviceid] )
)
RETURN
SWITCH (
CountProducts,
1, "Single Product",
"Multiple Products"
)
Рабочий пример файла PBIX: https://pwrbi.com/so_55918190/
Решение DAX для тестирования производительности, на 250 000 строк: