I have written two functions which take date as input and I'm gonna use them on multiple queries. Instead of doing manual work every time (call both functions, filter rows where first function returns True, expand record of the second function to columns, delete first function column) I thought I'd write another function that takes names of the table and the column with dates as parameters to automatize that process. My current table-based function works if I include specific column's date in the code, but those names will be different between different queries(tables).
Here's the table function's code:
(t as table) =>
let
FunctionFilter = Table.AddColumn(t, "DateFilter", each DateFilter([myDate2])),
FunctionPeriods = Table.AddColumn(#"FunctionFilter", "TimePeriods", each TimePeriods([myDate2])),
ExpandPeriods= Table.ExpandRecordColumn(FunctionPeriods, "TimePeriods", {"Year", "Quarter", "Month", "WeekMon", "WeekTue", "Day"},
{"Year", "Quarter", "Month", "WeekMon", "WeekTue", "Day"}),
TrueDate = Table.SelectRows(ExpandPeriods, each ([DateFilter] = true)),
DeleteDateFilter = Table.RemoveColumns(TrueDate,{"DateFilter"})
in
DeleteDateFilter
My only problem is inserting a variable column name in place of [myDate2] here:
FunctionFilter = Table.AddColumn(t, "DateFilter", each DateFilter([myDate2])),
FunctionPeriods = Table.AddColumn(#"FunctionFilter", "TimePeriods", each TimePeriods([myDate2])),
Using Table.Column(t,[column name]) returns a list instead of a date, which causes called date functions to throw a type mismatch error.