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
| import os | |
| import pandas as pd | |
| import pyodbc | |
| def check_and_create_folders(root, projects, folders): | |
| #for each project in the projects table | |
| for project in projects: | |
| #if the project number is not found in the directory | |
| if project not in folders: | |
| #make root folder |
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
| let | |
| fnSwitchContains = (string as text, switches as list, default as any) => | |
| let | |
| select = try List.Select(switches, each Text.Contains(string, _{0})){0}{1} otherwise default | |
| in | |
| select, | |
| fnType = type function (string as text, switches as list, default as text) as any | |
| meta [ | |
| Documentation.Name = "fnSwitchContains", | |
| Documentation.LongDescription |
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
| let fnSwitch = | |
| (string as text, switches as list, default as any) => | |
| let | |
| select = try List.Select(switches, each _{0} = string){0}{1} otherwise default | |
| in | |
| select, | |
| fnType = type function (string as text, switches as list, default as text) as any |
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
| // This version using scoping and conditional recursion. | |
| let | |
| fnSwitch = (string as text, switches as list, default as any) => | |
| let | |
| switch = (i) => | |
| // if the string matches the first item in the list | |
| if string = switches{i}{0} then | |
| // then grab the second item in that nested list |
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
| let | |
| fnSwitch = (string as text, switches as list, default as any) => | |
| let | |
| // Get max index of replacement list | |
| Max = List.Count(switches) - 1, | |
| // Use List.Accumulate to loop through replacements | |
| Switch = List.Accumulate( | |
| switches, | |
| default, | |
| // if the string matches first index, then replace with second item in that nested list |
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 datetime import date, timedelta | |
| from dateutil.relativedelta import relativedelta | |
| class DateGenerator: | |
| def __init__(self): | |
| self.fiscal_months = {1:10,2:11,3:12,4:1,5:2,6:3,7:4,8:5,9:6,10:7,11:8,12:9} | |
| self.current_month = date.today().month | |
| self.current_year = date.today().year | |
| self.current_date = date.today() |
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
| (batch as number, total as number, base as number) => | |
| let | |
| batches = List.Generate( | |
| ()=>[ | |
| from = base, | |
| to = batch | |
| ], | |
| each [to] <= total, |
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
| let fnCreateMultiDimID = | |
| (fact as table, dim as table) => | |
| let | |
| // Get column names minus the first column on the dim table, which should be the id | |
| Columns = List.Skip(Table.ColumnNames(dim),1), | |
| // Join the tables | |
| Join = Table.Join(fact, Columns, dim, Columns), |
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
| let | |
| fnCreateMultiColDim = (t as table, dim_groups as list, id_names as list) => | |
| let | |
| // This nested function creates the individual dimension tables within the List.Generate() run | |
| fnMakeDim = (tbl as table, dim_cols as list, id_name as text) => | |
| let | |
| // It add an index column after selecting the columns and deduplicating. | |
| ChooseAndProcess = Table.AddIndexColumn( | |
| Table.Distinct(Table.SelectColumns(t, dim_cols)), | |
| id_name, |
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
| (tbl as table, col_name as text, index_name as text)=> | |
| let | |
| removed_cols = Table.SelectColumns(tbl,{col_name}), | |
| dedupe = Table.Distinct(removed_cols), | |
| sorted = Table.Sort(dedupe,{{col_name, Order.Ascending}}), | |
| add_index = Table.AddIndexColumn(sorted, index_name, 1, 1, Int64.Type), | |
| order = Table.ReorderColumns(add_index,{index_name, col_name}) | |
| in | |
| order |