Fixed fP issue with self calling
This commit is contained in:
236
power-query/fP.m
236
power-query/fP.m
@@ -1,138 +1,140 @@
|
|||||||
(P_NAME as text, optional P_FORCED_TYPE as nullable text) => let
|
let
|
||||||
|
fP = (P_NAME as text, optional P_FORCED_TYPE as nullable text) => let
|
||||||
|
//Получаем параметр из таблицы с настройками
|
||||||
|
GET_PARAMETER = try
|
||||||
|
let
|
||||||
|
GetTable = Excel.CurrentWorkbook(){[Name="PARAMETERS_TABLE"]}[Content],
|
||||||
|
KeepNeeded = Table.SelectColumns(GetTable,{"ПАРАМЕТР", "ЗНАЧЕНИЕ","ТИП"}),
|
||||||
|
SetTypes = Table.TransformColumnTypes(KeepNeeded,{{"ПАРАМЕТР", type text}, {"ЗНАЧЕНИЕ", type any}, {"ТИП", type text}}),
|
||||||
|
Filter = Table.SelectRows(SetTypes, each ([ПАРАМЕТР] = P_NAME)),
|
||||||
|
Value = Table.SingleRow(Filter)
|
||||||
|
in
|
||||||
|
Value otherwise null,
|
||||||
|
|
||||||
//Получаем параметр из таблицы с настройками
|
PATH_OVERRIDE = try if P_NAME = "PATH_OVERRIDE" then null else @fP("PATH_OVERRIDE") otherwise null,
|
||||||
GET_PARAMETER = try
|
|
||||||
let
|
P_TYPE = if GET_PARAMETER <> null then
|
||||||
GetTable = Excel.CurrentWorkbook(){[Name="PARAMETERS_TABLE"]}[Content],
|
if P_FORCED_TYPE = null then GET_PARAMETER[ТИП] else P_FORCED_TYPE
|
||||||
KeepNeeded = Table.SelectColumns(GetTable,{"ПАРАМЕТР", "ЗНАЧЕНИЕ","ТИП"}),
|
else
|
||||||
SetTypes = Table.TransformColumnTypes(KeepNeeded,{{"ПАРАМЕТР", type text}, {"ЗНАЧЕНИЕ", type any}, {"ТИП", type text}}),
|
null,
|
||||||
Filter = Table.SelectRows(SetTypes, each ([ПАРАМЕТР] = P_NAME)),
|
|
||||||
Value = Table.SingleRow(Filter)
|
P_VALUE = if GET_PARAMETER <> null then
|
||||||
|
if PATH_OVERRIDE <> null and
|
||||||
|
List.Contains({"FILE", "EXCEL", "DIR", "PATH", "CSVL"}, P_TYPE) then
|
||||||
|
fReplaceFunction(GET_PARAMETER[ЗНАЧЕНИЕ], false, PATH_OVERRIDE )
|
||||||
|
else
|
||||||
|
GET_PARAMETER[ЗНАЧЕНИЕ]
|
||||||
|
else
|
||||||
|
null,
|
||||||
|
|
||||||
|
// Определяем функции
|
||||||
|
// БУЛЕВО
|
||||||
|
F_Boolean = (Input as any) => let
|
||||||
|
Result = Value.ReplaceType(Input, type logical)
|
||||||
in
|
in
|
||||||
Value otherwise null,
|
Result,
|
||||||
|
|
||||||
PATH_OVERRIDE = try if P_NAME = "PATH_OVERRIDE" then null else fP("PATH_OVERRIDE") otherwise null,
|
// ЦЕЛОЕ ЧИСЛО
|
||||||
|
F_Integer = (Input as any) => let
|
||||||
|
Result = Value.ReplaceType(Input, Int64.Type)
|
||||||
|
in
|
||||||
|
Result,
|
||||||
|
|
||||||
P_TYPE = if GET_PARAMETER <> null then
|
// ЧИСЛО С ЗАПЯТОЙ
|
||||||
if P_FORCED_TYPE = null then GET_PARAMETER[ТИП] else P_FORCED_TYPE
|
F_Float = (Input as any) => let
|
||||||
else
|
Result = Value.ReplaceType(Input, type number)
|
||||||
null,
|
in
|
||||||
|
Result,
|
||||||
|
|
||||||
P_VALUE = if GET_PARAMETER <> null then
|
// СТРОКА
|
||||||
if PATH_OVERRIDE <> null and
|
F_Text = (Input as any) => let
|
||||||
List.Contains({"FILE", "EXCEL", "DIR", "PATH", "CSVL"}, P_TYPE) then
|
Result = Value.ReplaceType(Input, type text)
|
||||||
fReplaceFunction(GET_PARAMETER[ЗНАЧЕНИЕ], false, PATH_OVERRIDE )
|
in
|
||||||
else
|
Result,
|
||||||
GET_PARAMETER[ЗНАЧЕНИЕ]
|
|
||||||
else
|
|
||||||
null,
|
|
||||||
|
|
||||||
// Определяем функции
|
// ДАТА
|
||||||
// БУЛЕВО
|
F_Date = (Input as any) => let
|
||||||
F_Boolean = (Input as any) => let
|
Result = Value.ReplaceType(DateTime.Date(Input), type date)
|
||||||
Result = Value.ReplaceType(Input, type logical)
|
in
|
||||||
in
|
Result,
|
||||||
Result,
|
|
||||||
|
|
||||||
// ЦЕЛОЕ ЧИСЛО
|
// ДАТА И ВРЕМЯ
|
||||||
F_Integer = (Input as any) => let
|
F_DateTime = (Input as any) => let
|
||||||
Result = Value.ReplaceType(Input, Int64.Type)
|
Result = Value.ReplaceType(Input, type datetime)
|
||||||
in
|
in
|
||||||
Result,
|
Result,
|
||||||
|
|
||||||
// ЧИСЛО С ЗАПЯТОЙ
|
// СПИСОК В ФОРМАТЕ PQ
|
||||||
F_Float = (Input as any) => let
|
F_List = (Input as any) => let
|
||||||
Result = Value.ReplaceType(Input, type number)
|
Result = Text.Split(Text.Replace(Text.From(Input), "; ", ";"), ";")
|
||||||
in
|
in
|
||||||
Result,
|
Result,
|
||||||
|
|
||||||
// СТРОКА
|
// ТАБЛИЦА В ФОРМАТЕ PQ
|
||||||
F_Text = (Input as any) => let
|
F_RcrdSet = (Input as any) => let
|
||||||
Result = Value.ReplaceType(Input, type text)
|
RemoveSpaces = Text.Replace(Text.Replace(Input, " ;", ";"), "; ", ";"),
|
||||||
in
|
SplitRows = Text.Split(RemoveSpaces, "};{"),
|
||||||
Result,
|
Replace = List.ReplaceValue(List.ReplaceValue(SplitRows,"}","",Replacer.ReplaceText),"{","",Replacer.ReplaceText),
|
||||||
|
Result = Table.FromList(Replace, Splitter.SplitTextByDelimiter(";"))
|
||||||
|
in
|
||||||
|
Result,
|
||||||
|
|
||||||
// ДАТА
|
// СПИСОК ЗАМЕН
|
||||||
F_Date = (Input as any) => let
|
F_Symlink = (Input as any) => let
|
||||||
Result = Value.ReplaceType(DateTime.Date(Input), type date)
|
RemoveSpaces = Text.Replace(Text.Replace(Input, " ;", ";"), "; ", ";"),
|
||||||
in
|
SplitRows = Text.Split(RemoveSpaces, ";"),
|
||||||
Result,
|
Result = Table.FromList(SplitRows, Splitter.SplitTextByDelimiter(">>"))
|
||||||
|
in
|
||||||
|
Result,
|
||||||
|
|
||||||
// ДАТА И ВРЕМЯ
|
// ФАЙЛ EXCEL
|
||||||
F_DateTime = (Input as any) => let
|
F_ExcelFile = (Input as any) => let
|
||||||
Result = Value.ReplaceType(Input, type datetime)
|
Result = Excel.Workbook(File.Contents(Input), null, true)
|
||||||
in
|
in
|
||||||
Result,
|
Result,
|
||||||
|
|
||||||
// СПИСОК В ФОРМАТЕ PQ
|
// СОДЕРЖИМОЕ ПАПКИ
|
||||||
F_List = (Input as any) => let
|
F_DirContent = (Input as any) => let
|
||||||
Result = Text.Split(Text.Replace(Text.From(Input), "; ", ";"), ";")
|
Result = Folder.Files(Input)
|
||||||
in
|
in
|
||||||
Result,
|
Result,
|
||||||
|
|
||||||
// ТАБЛИЦА В ФОРМАТЕ PQ
|
// ЛОКАЛЬНАЯ ИМЕНОВАННАЯ ТАБЛИЦА
|
||||||
F_RcrdSet = (Input as any) => let
|
F_LocalTable = (Input as any) => let
|
||||||
RemoveSpaces = Text.Replace(Text.Replace(Input, " ;", ";"), "; ", ";"),
|
Result = Excel.CurrentWorkbook(){[Name=Input]}[Content]
|
||||||
SplitRows = Text.Split(RemoveSpaces, "};{"),
|
in
|
||||||
Replace = List.ReplaceValue(List.ReplaceValue(SplitRows,"}","",Replacer.ReplaceText),"{","",Replacer.ReplaceText),
|
Result,
|
||||||
Result = Table.FromList(Replace, Splitter.SplitTextByDelimiter(";"))
|
|
||||||
in
|
|
||||||
Result,
|
|
||||||
|
|
||||||
// СПИСОК ЗАМЕН
|
// CSV-ФАЙЛ В СТАНДАРТНОЙ ПАПКЕ
|
||||||
F_Symlink = (Input as any) => let
|
F_LocalCSV = (Input as any) => let
|
||||||
RemoveSpaces = Text.Replace(Text.Replace(Input, " ;", ";"), "; ", ";"),
|
Result = Csv.Document(File.Contents("\\msk.mts.ru\msk\WORKDATA\OPSIMPAO-ANALYTICS\Aggregated CSV\" & Input & ".csv"), [Delimiter=",", Encoding=1251, QuoteStyle=QuoteStyle.None])
|
||||||
SplitRows = Text.Split(RemoveSpaces, ";"),
|
in
|
||||||
Result = Table.FromList(SplitRows, Splitter.SplitTextByDelimiter(">>"))
|
Result,
|
||||||
in
|
|
||||||
Result,
|
|
||||||
|
|
||||||
// ФАЙЛ EXCEL
|
CaseValues = {
|
||||||
F_ExcelFile = (Input as any) => let
|
{ List.Contains({"BOOL" , "LOGICAL" }, P_TYPE), try F_Boolean (P_VALUE) otherwise null},
|
||||||
Result = Excel.Workbook(File.Contents(Input), null, true)
|
{ List.Contains({"INT" , "INT64" }, P_TYPE), try F_Integer (P_VALUE) otherwise null},
|
||||||
in
|
{ List.Contains({"FLOAT" , "DOUBLE" }, P_TYPE), try F_Float (P_VALUE) otherwise null},
|
||||||
Result,
|
{ List.Contains({"TEXT" , "STRING" }, P_TYPE), try F_Text (P_VALUE) otherwise null},
|
||||||
|
{ List.Contains({"DATE" }, P_TYPE), try F_Date (P_VALUE) otherwise null},
|
||||||
|
{ List.Contains({"DATETIME", "DTTM" }, P_TYPE), try F_DateTime (P_VALUE) otherwise null},
|
||||||
|
|
||||||
// СОДЕРЖИМОЕ ПАПКИ
|
{ List.Contains({"LIST" }, P_TYPE), try F_List (P_VALUE) otherwise null},
|
||||||
F_DirContent = (Input as any) => let
|
{ List.Contains({"RCRDSET", "PQTABLE" }, P_TYPE), try F_RcrdSet (P_VALUE) otherwise null},
|
||||||
Result = Folder.Files(Input)
|
{ List.Contains({"SYMLNK" , "SYMLINK" }, P_TYPE), try F_Symlink (P_VALUE) otherwise null},
|
||||||
in
|
|
||||||
Result,
|
|
||||||
|
|
||||||
// ЛОКАЛЬНАЯ ИМЕНОВАННАЯ ТАБЛИЦА
|
{ List.Contains({"TABLE" }, P_TYPE), try F_LocalTable (P_VALUE) otherwise null},
|
||||||
F_LocalTable = (Input as any) => let
|
|
||||||
Result = Excel.CurrentWorkbook(){[Name=Input]}[Content]
|
|
||||||
in
|
|
||||||
Result,
|
|
||||||
|
|
||||||
// CSV-ФАЙЛ В СТАНДАРТНОЙ ПАПКЕ
|
{ List.Contains({"FILE" , "EXCEL" }, P_TYPE), try F_ExcelFile (P_VALUE) otherwise null},
|
||||||
F_LocalCSV = (Input as any) => let
|
{ List.Contains({"DIR" , "PATH" }, P_TYPE), try F_DirContent (P_VALUE) otherwise null},
|
||||||
Result = Csv.Document(File.Contents("\\msk.mts.ru\msk\WORKDATA\OPSIMPAO-ANALYTICS\Aggregated CSV\" & Input & ".csv"), [Delimiter=",", Encoding=1251, QuoteStyle=QuoteStyle.None])
|
{ List.Contains({"CSVL" }, P_TYPE), try F_LocalCSV (P_VALUE) otherwise null},
|
||||||
in
|
|
||||||
Result,
|
|
||||||
|
|
||||||
CaseValues = {
|
{ true , P_VALUE }
|
||||||
{ List.Contains({"BOOL" , "LOGICAL" }, P_TYPE), try F_Boolean (P_VALUE) otherwise null},
|
},
|
||||||
{ List.Contains({"INT" , "INT64" }, P_TYPE), try F_Integer (P_VALUE) otherwise null},
|
|
||||||
{ List.Contains({"FLOAT" , "DOUBLE" }, P_TYPE), try F_Float (P_VALUE) otherwise null},
|
|
||||||
{ List.Contains({"TEXT" , "STRING" }, P_TYPE), try F_Text (P_VALUE) otherwise null},
|
|
||||||
{ List.Contains({"DATE" }, P_TYPE), try F_Date (P_VALUE) otherwise null},
|
|
||||||
{ List.Contains({"DATETIME", "DTTM" }, P_TYPE), try F_DateTime (P_VALUE) otherwise null},
|
|
||||||
|
|
||||||
{ List.Contains({"LIST" }, P_TYPE), try F_List (P_VALUE) otherwise null},
|
SelectCase = List.First(List.Select(CaseValues, each _{0} = true)){1}
|
||||||
{ List.Contains({"RCRDSET", "PQTABLE" }, P_TYPE), try F_RcrdSet (P_VALUE) otherwise null},
|
|
||||||
{ List.Contains({"SYMLNK" , "SYMLINK" }, P_TYPE), try F_Symlink (P_VALUE) otherwise null},
|
|
||||||
|
|
||||||
{ List.Contains({"TABLE" }, P_TYPE), try F_LocalTable (P_VALUE) otherwise null},
|
in
|
||||||
|
SelectCase
|
||||||
{ List.Contains({"FILE" , "EXCEL" }, P_TYPE), try F_ExcelFile (P_VALUE) otherwise null},
|
in
|
||||||
{ List.Contains({"DIR" , "PATH" }, P_TYPE), try F_DirContent (P_VALUE) otherwise null},
|
fP
|
||||||
{ List.Contains({"CSVL" }, P_TYPE), try F_LocalCSV (P_VALUE) otherwise null},
|
|
||||||
|
|
||||||
{ true , P_VALUE }
|
|
||||||
},
|
|
||||||
|
|
||||||
SelectCase = List.First(List.Select(CaseValues, each _{0} = true)){1}
|
|
||||||
|
|
||||||
in
|
|
||||||
SelectCase
|
|
||||||
Reference in New Issue
Block a user