Forum Discussion
Help with Query (Greater than)
- 4 years ago
NewStep= let fx=(t)=>let a=Text.From(t),b=List.PositionOf(Text.ToList(a&"a"),"",0,each List.Contains({"0".."9"},_)),c=Splitter.SplitTextByPositions({0,b})(a) in {Number.From(c{0}),Text.Start(c{1},1)} in Table.AddColumn(PreviousStepName,"Check",each let a=fx([Col A]),b=fx([Col B]),c=if a{0}<>b{0} then Value.Compare(a{0},b{0}) else Value.Compare(a{1},b{1}) in if a{0}=null and b{0}=null then "None" else if c=-1 then "Col B greater" else if c=0 then "Matches" else "Col A greater")
- 4 years ago
OK. It looks like my initial suggestion of padding with "0" was closer to correct. The difficulty is that the padding expands "A" and "0A" to be the same thing but you want these treated differently when compared to "0". I.e., "0" > "A" but "0" < "0A".
Try this with the digits and the letters treated separately:
let DigitsA = Number.FromText(Text.Select([Col A], {"0".."9"})) ?? -1, DigitsB = Number.FromText(Text.Select([Col B], {"0".."9"})) ?? -1, LettersA = Text.Remove([Col A], {"0".."9"}), LettersB = Text.Remove([Col B], {"0".."9"}), Result = if [Col A] = [Col B] then "Matches" else if DigitsA > DigitsB then "Col A greater" else if DigitsA = DigitsB and LettersA > LettersB then "Col A greater" else "Col B greater" in ResultNote: The ?? -1 syntax replaces nulls with -1.
OK. It looks like my initial suggestion of padding with "0" was closer to correct. The difficulty is that the padding expands "A" and "0A" to be the same thing but you want these treated differently when compared to "0". I.e., "0" > "A" but "0" < "0A".
Try this with the digits and the letters treated separately:
let
DigitsA = Number.FromText(Text.Select([Col A], {"0".."9"})) ?? -1,
DigitsB = Number.FromText(Text.Select([Col B], {"0".."9"})) ?? -1,
LettersA = Text.Remove([Col A], {"0".."9"}),
LettersB = Text.Remove([Col B], {"0".."9"}),
Result = if [Col A] = [Col B] then "Matches"
else if DigitsA > DigitsB then "Col A greater"
else if DigitsA = DigitsB and LettersA > LettersB then "Col A greater"
else "Col B greater"
in
Result
Note: The ?? -1 syntax replaces nulls with -1.
Works perfectly š Thanks a lot. This saves me an extra set of coding!
Much appreciated š