Forum Discussion
ftb1ss
Apr 02, 2021Copper Contributor
Counting names
I am using a PC w/Windows 10 and MS 365. I have a workbook with 12 sheets, one for each month of the year. On each worksheet I have a list of all the people who have attended a meeting. Each line ...
SergeiBaklan
Apr 04, 2021Diamond Contributor
ftb1ss As variant that could be done by Power Query.
- name range for each month
- add function which takes the month and clean the data
(month as text) =>
let
Source = Excel.CurrentWorkbook(){[Name=month]}[Content],
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Removed Other Columns" = Table.SelectColumns(#"Promoted Headers",{"Last", "First", "NCRR"}),
#"Filtered Rows" = Table.SelectRows(#"Removed Other Columns", each ([Last] <> null))
in
#"Filtered Rows"
- combine months
let
Source = Table.Combine(
{
fnGetMonth("Mar"),
fnGetMonth("Apr")
}
)
in
Source
- count by NCPR
let
Source = #"Combine months",
#"Grouped Rows" = Table.Group(
Source,
{"NCRR"},
{{"Count", each Table.RowCount(_), Int64.Type}}
)
in
#"Grouped Rows"
in general that could be all, but names are spelled differently in different months, thus we map Names on NCPR
- takes names and remove duplicated NCPR
let
Source = #"Combine months",
#"Removed Duplicates" = Table.Distinct(Source, {"NCRR"})
in
#"Removed Duplicates"
- merge names with counts using NCPR as the key
let
Source = Table.NestedJoin(
Names, {"NCRR"},
Counts, {"NCRR"},
"Counts", JoinKind.LeftOuter
),
#"Expanded Counts" = Table.ExpandTableColumn(
Source, "Counts",
{"Count"}, {"Count"}
)
in
#"Expanded Counts"
Now that's all.