Forum Discussion
ambi95
3 years agoHelper I
Excel formula to power query M code
Hi all, Im trying to convert the following formula in excel to M code : =CONCATENATE(H2, MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",( IFERROR(IF(FIND(MID(H2,1,1),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,...
ppm1
3 years agoSolution Sage
Can you give an example of an input string with the expected output? The one shown isn't clear.
Pat
- ppm13 years agoSolution Sage
This is fairly complex but it does match the Excel result (when all the letters are upper case). Add a custom column and put the code below in the pop-up box, replacing TextColumn with the name of your text input column.
let input = Text.Upper([TextColumn]), letters = {"A".."Z"}, concatvalues = {null, "A".."Z", "0".."5"}, splitinput = List.Split(Text.ToList(input), 5), lettercheck = List.Transform(splitinput, (x)=> List.Transform(x, (y)=> Number.From(List.Contains(letters, y) ))), multipliers = {1,2,4,8,16}, listsums = List.Transform(lettercheck, (a)=> List.Sum(List.Transform({0..4}, (b)=> a{b}*multipliers{b}))), listvalues = List.Transform(listsums, each concatvalues{_+1}), result = input & Text.Combine(listvalues, "") in resultPat