Forum Discussion
Anonymous
5 years agoNot applicable
Power Query / Power pivot countifs from multiple tables
I have 2 tables with a bunch of data, corresponding in two columns with Attribute1 and date. I'd like to create a table that: - has two columns with the unique combinations of Date and Atrribute...
ziying35
5 years agoImpactful Individual
Hi, Anonymous
Try this:
// fx
(tbl_name)=>
let
Source = Excel.CurrentWorkbook(){[Name=tbl_name]}[Content],
group = Table.Group(Source, {"Date", "Attribute"}, {{"Count_"&Text.Select(tbl_name, {"0".."9"}), each Table.RowCount(_), Int64.Type}})
in
group
// output
let
Source = List.Transform({"Table_1", "Table_2"}, fx),
fnTrans = (tbl)=>
Record.Combine(
List.Transform(
List.Skip(Table.ColumnNames(tbl),2),
each Record.FromList(
{List.Last(List.RemoveNulls(Table.Column(tbl, _)), null)},
{_}
)
)
),
tblCmb = Table.Combine(Source),
group = Table.Group(tblCmb, {"Date", "Attribute"}, {"t", fnTrans}),
expd = Table.ExpandRecordColumn(group, "t", {"Count_1", "Count_2"}),
sort = Table.Sort(expd,{{"Date", Order.Ascending}}),
chType = Table.TransformColumnTypes(sort,{{"Date", type date}})
in
chType
Paste my two query codes directly into the Power Query editor of the Excel file you provided as an example, and follow the screenshot below:
If you want the date to be displayed as in the example you provided, it is recommended to set it in the Excel worksheet by Format Cells.
- Anonymous5 years agoNot applicable
Thank you for the reply! I need to take some time to properly go through it and understand it though.
- Jimmy8015 years agoCommunity Champion
Hello Anonymous
good luck. Waiting for your feedback then
BR
Jimmy