Forum Discussion
Calculate count in Matrix visual in PowerBI Desktop
- Anonymous1 year ago
Hi, vickychill
Thanks for the reply from Bibiano_Geraldo. You can refer to the following methods to achieve your need.
Method 1:And then modify the Subtotal label in the Column subtotals.
Counts = VAR _FruitVeg = MAX('Table'[Fruit/Veg]) VAR _counts = COUNT('Table'[Fruit/Veg]) RETURN IF(ISINSCOPE('Table'[Name]),_FruitVeg,_counts)
Method 2:
Create a dim table in Power Query:let Source = Table, #"Removed Other Columns" = Table.SelectColumns(Source,{"Name"}), #"Removed Duplicates" = List.Combine( {{"Count"},Table.Distinct(#"Removed Other Columns")[Name]}), #"Converted to Table" = Table.FromList(#"Removed Duplicates", Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Added Index" = Table.AddIndexColumn(#"Converted to Table", "Index", 0, 1, Int64.Type) in #"Added Index"Then use this measure:
Measure = VAR __cur_column = SELECTEDVALUE('Table (2)'[Column1]) VAR __result = IF( __cur_column<> "Count", CALCULATE(MAX('Table'[Fruit/Veg]),'Table'[Name]=__cur_column), CALCULATE(COUNTROWS('Table'))) RETURN __result
Best Regards,
Yang
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Hi, vickychill
Thanks for the reply from Bibiano_Geraldo. You can refer to the following methods to achieve your need.
Method 1:
And then modify the Subtotal label in the Column subtotals.
Counts =
VAR _FruitVeg = MAX('Table'[Fruit/Veg])
VAR _counts = COUNT('Table'[Fruit/Veg])
RETURN
IF(ISINSCOPE('Table'[Name]),_FruitVeg,_counts)
Method 2:
Create a dim table in Power Query:
let
Source = Table,
#"Removed Other Columns" = Table.SelectColumns(Source,{"Name"}),
#"Removed Duplicates" = List.Combine( {{"Count"},Table.Distinct(#"Removed Other Columns")[Name]}),
#"Converted to Table" = Table.FromList(#"Removed Duplicates", Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Index" = Table.AddIndexColumn(#"Converted to Table", "Index", 0, 1, Int64.Type)
in
#"Added Index"
Then use this measure:
Measure =
VAR __cur_column = SELECTEDVALUE('Table (2)'[Column1])
VAR __result = IF( __cur_column<> "Count", CALCULATE(MAX('Table'[Fruit/Veg]),'Table'[Name]=__cur_column), CALCULATE(COUNTROWS('Table')))
RETURN
__result
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum