Forum Discussion
Power Query / Power pivot countifs from multiple tables
Hello Anonymous
check out this solution. Should be a bit easier to understand. Be aware that it contains also two datasets of tables. Also in order that everyone can try it. Just substitute theses datasets with your Excel-tables
let
Table1 =
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUMzDSMzJQ0lFyUorVAQoYoQsYwwUcIQIm6AKm6AJmcAFnpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Atribute = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date, "de-DE"}, {"Atribute", type text}})
in
#"Changed Type",
Table2 =
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUMzDSMzJQ0lFyUorVAQoYwQVc0AWIVmGMLBALAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Atribute = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date, "de-DE"}, {"Atribute", type text}})
in
#"Changed Type",
CombineAndDistinct = Table.Distinct(Table.Combine({Table1,Table2})),
AddCountForTable1 = Table.AddColumn
(
CombineAndDistinct,
"Count Table1",
(addrec)=> Table.RowCount(Table.SelectRows(Table1, each Record.SelectFields(_, {"Date", "Atribute"}) = Record.SelectFields(addrec, {"Date", "Atribute"}) ))
),
AddCountForTable2 = Table.AddColumn
(
AddCountForTable1,
"Count Table2",
(addrec)=> Table.RowCount(Table.SelectRows(Table2, each Record.SelectFields(_, {"Date", "Atribute"}) = Record.SelectFields(addrec, {"Date", "Atribute"}) ))
)
in
AddCountForTable2
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
- Anonymous5 years agoNot applicable
Thank you for the reply!
What I ended up doing was starting a blank query and basically doing source = table1 & table2 & table3 etc., and going from there.
Am I correct in understanding your code basically does the same? Is there a speed difference when refreshing the query?
Because I've discovered I can build most of the (what would probably considerd rather rudimentary) tables I need with the Power Query GUI, but it is speed that is severely bottlenecking me now. As a result of several query merges, and then referencing these queries ~20 times to make ~20 small grouped by tables in a simple dashboard, I'm finding that excel seems to recalculate the referenced query every time before it does a new group by (if that makes any sense), allowing me to go for a walk for ~10 mins.