Forum Discussion

dobregon's avatar
dobregon
Impactful Individual
6 years ago

replace multiple values list in the same table

Hi guys,

 

I have a doubt about M querys, i'm looking to apply a custom column in a table that replace values from a column loking for the list values in the same table, te table is something like this

IdParentIdHierarchyOrderPath
1NULLExpected11
2NULLIncomes22
32Bike12|3
42Motorbike22|4
52Losses32|5
65Theft12|5|6
75Broken22|5|7


And what i want is to analyse the column Path, each number look into the id column and give the order column and the result should be something like this 

 

IdParentIdHierarchyOrderPathOrderPath
1NULLExpected111
2NULLIncomes222
32Bike12|32|1
42Motorbike22|42|2
52Losses32|52|3
65Theft12|5|62|3|1
75Broken22|5|72|3|2


It could be possible to do in a custom column without creating other tables? i have tried some examples like 

https://www.thebiccountant.com/2016/05/22/multiple-replacements-in-power-bi-and-power-query/ 

but they are not running taking the info from the same table.

 

Someone can help me? thanks

10 Replies

  • Nathaniel_C's avatar
    Nathaniel_C
    Community Champion

    Hi dobregon ,
    Can you give us the logic? Something like if this then do this, if that, then do that.
    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos πŸ‘are nice too.
    Nathaniel

    • dobregon's avatar
      dobregon
      Impactful Individual

      thanks for the refply Nathaniel_C , the logic should be something that search all the numbers in the path and if the number exists (that should be) in the id, the number should be replaced by the numer in the order column

      So, the text to analyse is the column path
      the oldvalues are in the column ID

      the newvalues are in the column Order

      • Jimmy801's avatar
        Jimmy801
        Community Champion

        Hello dobregon 

         

        you can use this formula in your new custom colum

        if Text.Contains([Path], [Id]) = true then Text.Replace([Path], [Id], [Order]) else [Path]

         

        Have fun

         

        Jimmy

         

        It this helps, consider marking this post as solution or like it