Forum Discussion
NBEN66
3 years agoFrequent Visitor
Dynamically import custom functions
Hello Everyone, At our company we are trying to automate customer orders that are sent in via PDF. We have hundreds of customer with different PDF templates. We decided to use Power query PDF im...
- 3 years ago
Hello - yes, this can be done. Here is an example:
let //Load M code from text file Source = Text.FromBinary(File.Contents("C:\PathToYourFile.txt")), //Evaluate the code from the file as an M expression EvaluatedExpression = Expression.Evaluate(Source, #shared) in EvaluatedExpression
jennratten
3 years agoSuper User
Hello - yes, this can be done. Here is an example:
let
//Load M code from text file
Source = Text.FromBinary(File.Contents("C:\PathToYourFile.txt")),
//Evaluate the code from the file as an M expression
EvaluatedExpression = Expression.Evaluate(Source, #shared)
in
EvaluatedExpression Karthikeyan_S
2 years agoNew Member
May I know how to save the content of txt file contains custom functions?
- dufoq32 years agoCommunity Champion
Hi Karthikeyan_S, this way: (you can see 2 functions there excelTrim and fnShiftRows)
[ excelTrim = (textToTrim) => let fn = [ v_split = Text.Split(Text.From(textToTrim), " "), v_select = List.Select(v_split, each Text.Length(_) > 0), v_combine = Text.Combine(v_select, " ") ][v_combine] in fn, fnShiftRows = (tbl as table, col as text, shift as nullable number, optional newColName as text) as table => //v 3. parametri zadaj zaporne cislo ak chces posunut riadky hore, kladne ak dole, 4. je nepovinny (novy nazov stlpca) let a = Table.Column(tbl, col), b = if shift = 0 or shift = null then a else if shift > 0 then List.Repeat({null}, shift) & List.RemoveLastN(a, shift) else List.RemoveFirstN(a, shift * -1) & List.Repeat({null}, shift * -1), c = Table.FromColumns(Table.ToColumns(tbl) & {b}, Table.ColumnNames(tbl) & ( if newColName <> null then {newColName} else if shift = 0 then {col & "_Duplicate"} else if shift > 0 then {col & "_PrevValue"} else {col & "_NextValue"} )) in c ]