Add new Power Query functions and update settings for improved data handling
This commit is contained in:
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"powerquery.client.additionalSymbolsDirectories": [
|
||||
"d:/Onedrive/Projects/Own Code/spqr/.vscode/excel-pq-symbols"
|
||||
]
|
||||
}
|
||||
20
power-query/fFixCSVDates.m
Normal file
20
power-query/fFixCSVDates.m
Normal file
@@ -0,0 +1,20 @@
|
||||
let
|
||||
Func = (SourceText as nullable text) as date =>
|
||||
let
|
||||
CheckSlashes = Text.Contains(SourceText, "/"),
|
||||
TryToConvert = if CheckSlashes then
|
||||
let
|
||||
SplitText = Text.Split(SourceText, "/"),
|
||||
Parse = try Date.From(#date(Number.From(SplitText{2}),
|
||||
Number.From(SplitText{0}),
|
||||
Number.From(SplitText{1})
|
||||
) )
|
||||
otherwise null
|
||||
in
|
||||
Parse
|
||||
else
|
||||
Date.From(SourceText)
|
||||
in
|
||||
TryToConvert
|
||||
in
|
||||
Func
|
||||
19
power-query/fFixCSVNumbers
Normal file
19
power-query/fFixCSVNumbers
Normal file
@@ -0,0 +1,19 @@
|
||||
let
|
||||
Func = (TableOrText as any, optional ColumnsList as list) => let
|
||||
ChooseMethod = try List.IsEmpty(ColumnsList) otherwise true,
|
||||
ApplyMethod = if ChooseMethod then
|
||||
let
|
||||
ColonToNull = Text.Replace(TableOrText, ",", ""),
|
||||
DotToColon = Text.Replace(ColonToNull, ".", "")
|
||||
in
|
||||
DotToColon
|
||||
else
|
||||
let
|
||||
ColonToNull = Table.ReplaceValue(TableOrText, ",", "" , Replacer.ReplaceText, ColumnsList),
|
||||
DotToColon = Table.ReplaceValue(ColonToNull, ".", ",", Replacer.ReplaceText, ColumnsList)
|
||||
in
|
||||
DotToColon
|
||||
in
|
||||
ApplyMethod
|
||||
in
|
||||
Func
|
||||
7
power-query/fIfBlank.m
Normal file
7
power-query/fIfBlank.m
Normal file
@@ -0,0 +1,7 @@
|
||||
let
|
||||
GetData = (P_PRIMARY as nullable text, P_SECONDARY as nullable text) => let
|
||||
Makechoice = if P_PRIMARY is null then P_SECONDARY else P_PRIMARY
|
||||
in
|
||||
Makechoice
|
||||
in
|
||||
GetData
|
||||
8
power-query/specific/fDummyTable.m
Normal file
8
power-query/specific/fDummyTable.m
Normal file
@@ -0,0 +1,8 @@
|
||||
(optional LST_DUMMY_DATA as nullable list,
|
||||
optional LST_COLUMNS as nullable list) as table =>
|
||||
let
|
||||
DummyColumns = if LST_COLUMNS = null then LST_DUMMY_DATA else LST_COLUMNS,
|
||||
DummyData = if LST_DUMMY_DATA = null then List.Repeat({null}, List.Count(DummyColumns)) else LST_DUMMY_DATA,
|
||||
Dummy = #table(DummyColumns, {DummyData})
|
||||
in
|
||||
Dummy
|
||||
5
power-query/specific/fGetNeededColumnNames.m
Normal file
5
power-query/specific/fGetNeededColumnNames.m
Normal file
@@ -0,0 +1,5 @@
|
||||
(optional S_RENAME_TAG as text) as list =>
|
||||
let
|
||||
ColumnsToKeep = Table.Distinct(Table.SelectColumns(Table.SelectRows(fP("RENAMING_RULES"), each ([#"#"] = S_RENAME_TAG)),{"НОВЫЙ"}))[НОВЫЙ]
|
||||
in
|
||||
ColumnsToKeep
|
||||
22
power-query/specific/fNormalizeColumnNames.m
Normal file
22
power-query/specific/fNormalizeColumnNames.m
Normal file
@@ -0,0 +1,22 @@
|
||||
( TBL_SOURCE as table,
|
||||
optional S_RENAME_TAG as nullable text,
|
||||
optional B_DO_RENAME as nullable logical) as table =>
|
||||
let
|
||||
RenamingNeeded = if B_DO_RENAME = null then true else B_DO_RENAME,
|
||||
RenameTag = if S_RENAME_TAG = null then "" else S_RENAME_TAG,
|
||||
|
||||
InitialColumnNames = Table.ColumnNames(TBL_SOURCE),
|
||||
RenameTableColumns = if RenamingNeeded then
|
||||
let
|
||||
NewColumnNames = List.Transform(InitialColumnNames, each fReplaceFunction(_, true, S_RENAME_TAG)),
|
||||
RenameColumns = Table.RenameColumns(TBL_SOURCE,
|
||||
List.Zip({InitialColumnNames, NewColumnNames}))
|
||||
in
|
||||
RenameColumns
|
||||
else
|
||||
TBL_SOURCE,
|
||||
|
||||
ColumnsToKeep = fGetNeededColumnNames(RenameTag),
|
||||
KeepNeeded = Table.SelectColumns(RenameTableColumns, ColumnsToKeep, MissingField.Ignore)
|
||||
in
|
||||
KeepNeeded
|
||||
9
power-query/specific/fNormalizeMalfCode.m
Normal file
9
power-query/specific/fNormalizeMalfCode.m
Normal file
@@ -0,0 +1,9 @@
|
||||
let
|
||||
Source = (anyCode as nullable any) as text => let
|
||||
TrimCode = try Text.Trim(Text.From(anyCode)) otherwise "PARSE-ERROR",
|
||||
MarkNulls = if (TrimCode = null) or (TrimCode = "") or (TrimCode = "0") then "NOT-PROVIDED" else TrimCode,
|
||||
Normalize = try Text.Upper(MarkNulls) otherwise "PARSE-ERROR"
|
||||
in
|
||||
Normalize
|
||||
in
|
||||
Source
|
||||
10
power-query/specific/fNormalizeSKU.m
Normal file
10
power-query/specific/fNormalizeSKU.m
Normal file
@@ -0,0 +1,10 @@
|
||||
let
|
||||
Source = (anySKU as any) as number => let
|
||||
RemoveFullStop = Text.Replace(Text.From(anySKU), ".", ""),
|
||||
TrimSKU = Text.Trim(RemoveFullStop),
|
||||
MarkNulls = if (TrimSKU = null) or (TrimSKU = "") or (TrimSKU = "0") then -36001 else TrimSKU,
|
||||
Normalize = try Number.From(MarkNulls) otherwise -36002
|
||||
in
|
||||
Normalize
|
||||
in
|
||||
Source
|
||||
9
power-query/specific/fNormalizeSN.m
Normal file
9
power-query/specific/fNormalizeSN.m
Normal file
@@ -0,0 +1,9 @@
|
||||
let
|
||||
Source = (anySN as nullable any) as text => let
|
||||
TrimSN = try Text.Trim(Text.From(anySN)) otherwise "-36002",
|
||||
MarkNulls = if (TrimSN = null) or (TrimSN = "") or (TrimSN = "0") then "-36001" else TrimSN,
|
||||
Normalize = try Text.Upper(MarkNulls) otherwise "-36002"
|
||||
in
|
||||
Normalize
|
||||
in
|
||||
Source
|
||||
Reference in New Issue
Block a user