Created
February 6, 2023 16:01
-
-
Save ncalm/31fd444d22b28cdcd54c1ee4426145ac to your computer and use it in GitHub Desktop.
Custom Power Query function for creating lists of dates between two endpoints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (from as date, to as date, step_function as function) as list => | |
| let | |
| endpoint_function | |
| = (step_function as function) as function => | |
| (date as date) as number => | |
| let lookup = | |
| { | |
| {Date.AddDays, Number.From(date)}, | |
| {Date.AddMonths, Date.Year(date)*12 + Date.Month(date)}, | |
| {Date.AddQuarters, Date.Year(date)*4 + Date.QuarterOfYear(date)}, | |
| {Date.AddWeeks, Date.Year(date)*52 + Date.WeekOfYear(date)}, | |
| {Date.AddYears, Date.Year(date)} | |
| } | |
| in List.Select(lookup, each _{0} = step_function){0}{1}, | |
| fn = endpoint_function(step_function), | |
| Steps = fn(to) - fn(from), | |
| Transformer = (element as number) => step_function(from,element), | |
| NumberList = {0..Steps}, | |
| Result = List.Transform(NumberList, Transformer) | |
| in | |
| Result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment