Forum Discussion
Power Query find minimum/maximum dates across multiple tables
- 10 years ago
Btw, looks like there's a slight confusion in the function signature:
FnMinMaxDate = (TableName as table, ColumnName as text)
Do you want your first parameter to be table, or a table name? Looking at your parameters name and your input table, you're passing down the table's name (text), but your parameter type is table. I would recommend passing the table itself, instead of its name (check Table.Column's input parameters). So it should look like this:
FnMinMaxDate = (InputTable as table, ColumnName as text)
And your input table:
Table
Name(table) ColumnName(text)------------------------ ------------------
Sales SalesDate
Sales OrderDate
Purchase PurchaseDate
Does this make sense?
- 10 years ago
And then, what you need is probably to call Table.AddColumn function (in the query editor, you would see a button "Add Custom Column" for it)
you would call it in a way like this:
= Table.AddColumn(tableWithTablesAndColumnNames, "MinAndMax", each FnMinMaxDate([Table], [ColumnName]))
One other thing, if you're returning only 1 row, consider returning just a record instead of a table with 1 row.
About how to create a table with tables in it, #table function is an easy way in M
table1 = ..
table2 = ...
table3 = ...
tablesTable = #table({"first column name", "second column name"
] , { {table1, columnname1], {..], {..] ..
(replace ]s with closing curly braces, there's a forum bug that swallows my code apparently :) )
I used Table.FromRecords function to create my table and then call my custom function with values from this table.
Thanks again.
- sdjensen10 years agoSolution Sage
If anyone should read this I will not recommend this approach to anyone.
Power Query can't optimize the query for this, so when you use a table like this it will get the full table twice from the source instead of noticing "Hey, this query use a table I will get in another query, so I will go get the table content there first".