Forum Discussion
LoonaMoon
3 years agoFrequent Visitor
Use List.Number to generate dates in a loop
Hi everyone, I'm trying to generate calendar of holidays for the next 6 years. Where I live, it is a common practice to add an extra day to a holiday if the actual holiday occures on weekends. Fo...
- 3 years ago
Hi LoonaMoon ,
I would recommend looking for state holidays on your government's website and either scrape that or download from the endpoint.
For example, I'm in the UK and the GOV website has the following endpoint: https://www.gov.uk/bank-holidays.json
Using this, I just run the following query in a dataflow each night to have the most up-to-date listings:
let Source = Json.Document(Web.Contents("https://www.gov.uk/bank-holidays.json")), toList = Record.ToList(Source), toTable = Table.FromRecords(toList), expandEandWevents = toTable{0}[events], toTable2 = Table.FromList(expandEandWevents, Splitter.SplitByNothing(), null, null, ExtraValues.Error), expandRecords = Table.ExpandRecordColumn(toTable2, "Column1", {"title", "date", "notes", "bunting"}, {"title", "date", "notes", "bunting"}), remOthCols = Table.SelectColumns(expandRecords, {"date", "title", "notes"}), repQE2Funeral = Table.ReplaceValue(remOthCols, "Bank Holiday for the State Funeral of Queen Elizabeth II", "QE2 State Funeral BH", Replacer.ReplaceValue, {"title"}), repKC3Coronation = Table.ReplaceValue(repQE2Funeral, "Bank holiday for the coronation of King Charles III", "KC3 Coronation BH", Replacer.ReplaceValue, {"title"}), repBankHol1 = Table.ReplaceValue(repKC3Coronation, "bank holiday", "BH", Replacer.ReplaceText, {"title"}), repBankHol2 = Table.ReplaceValue(repBankHol1, "Bank Holiday", "BH", Replacer.ReplaceText, {"title"}), repBankHol3 = Table.ReplaceValue(repBankHol2, "Bank holiday", "BH", Replacer.ReplaceText, {"title"}), chgTypes = Table.TransformColumnTypes(repBankHol3,{{"title", type text}, {"date", type date}, {"notes", type text}}), renCols = Table.RenameColumns(chgTypes, {{"title", "holiday"}}) in renColsQuery output:
Pete
AlienSx
3 years agoSuper User
Hello, LoonaMoon . So you have a code for single year, right? Then
- create a custom function out of your code with holidays table and year as parameters.
- generate a list of years {year_from..year_to}.
- transform this list List.Transform(years_list, each function_name(holidays, _)).
- and finally List.Combine to get a single table with all your dates.