Add new Power Query functions and update settings for improved data handling

This commit is contained in:
2026-04-16 16:35:03 +03:00
parent 29b935a597
commit 1070653679
11 changed files with 114 additions and 0 deletions

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"powerquery.client.additionalSymbolsDirectories": [
"d:/Onedrive/Projects/Own Code/spqr/.vscode/excel-pq-symbols"
]
}

View 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

View 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

View File

7
power-query/fIfBlank.m Normal file
View 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

View 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

View 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

View 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

View 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

View 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

View 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