Hi James
Hope this helps.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcitKzEtOVdJRMjIwMtA3MgSy3FPzi9JBQm6Z+XmJSrE60UrBBYmZeSiKIHI6Sgpg+VBvFEmPxKKiSpCiotQUsDyyLYb6RkYwOZhSNDugSmDGoNqBqh/qWHRLjFAdooBugxGaV1GtwCIbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Country = _t, Year = _t, Primary = _t, Secondary = _t]),
DataType = Table.TransformColumnTypes(Source,{{"Country", type text}, {"Year", type text}, {"Primary", type text}, {"Secondary", type text}}),
Unpivoted = Table.UnpivotOtherColumns(DataType, {"Country", "Year"}, "Attribute","Name"),
FilteredBlankRows = Table.SelectRows(Unpivoted, each ([Name] <> " ")),
GroupedRows = Table.Group(FilteredBlankRows, {"Name", "Year", "Country"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
GroupedRows

------------------------------
Naveen Ajmera
PowerBiinDubai.com
Dubai
------------------------------
Original Message:
Sent: Jan 17, 2022 10:43 AM
From: James Lamb
Subject: Count occurrences over 2 columns and allow filter
I'm fairly new to PowerBI so bear with me please.
I have a data table and trying to summarise it so it counts the occurrence of the users name in primary and secondary column producing total occurrences and by year. Could anyone offer advice on how best to achieve please?
Table: Raw Data | | |
Country | Year | Primary | Secondary |
France | 2020/21 | George | Fiona |
Spain | 2020/21 | Fiona | |
UK | 2020/21 | Harry | Fred |
France | 2021/22 | Fred | Harry |
Spain | 2021/22 | Harry | |
UK | 2021/22 | Fred | George |
France | 2022/21 | Harry | |
Spain | 2022/21 | George | |
UK | 2022/21 | George | |
This is what I'm trying to get to:
Table: Yearly summary | | |
Name | 2020/21 | 2021/22 | 2022/21 | Total |
Harry | 1 | 2 | 1 | 4 |
Fred | 1 | 2 | 0 | 3 |
George | 1 | 1 | 2 | 4 |
Fiona | 2 | 0 | 0 | 2 |
Total | 5 | 5 | 3 | 13 |
------------------------------
James Lamb
------------------------------