Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dobregon
Impactful Individual
Impactful Individual

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



Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)
10 REPLIES 10
Nathaniel_C
Super User
Super User

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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



Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

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

Hi @Jimmy801 ,
Where does the three come from in the last row?
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Good question @Nathaniel_C 

i didn't even look at it.. simple implemented the request specified by @dobregon .

Maybe table is wrong or we will get a new logic.. lets wait 😉

 

Have a nice time

Jimmy

dobregon
Impactful Individual
Impactful Individual

@Jimmy801 & @Nathaniel_C  thanks a lot for your replies and see the error in the last row ajaja now it is corrected the parent id is 5.

Related to your query @Jimmy801  this function only substitute the values in that can find in the row, what i want is to do something like this in the same table (not creating 2-3 tables in the powerquery)
https://www.thebiccountant.com/2016/05/22/multiple-replacements-in-power-bi-and-power-query/ 

The path is the hierarchy based on the Id and ParentId, and what i want is to create another column based on the Path column and check every number in the path for the list of IDs that i have and susbitute taking the Order.

I have done something sumilar using this link example but only it is possible if i create 2 tables, the principal table and the other with only IDs and Order column. I'm looking if it is possible to create "virtual" buffer table with that info (IDs, Order) and then apply the recursive function



Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Hello @dobregon 

 

this actually hasn't to do anything with your orignal request, to replace values. Here we are taking about another logic to show a hierarchy. order Path it's difficult to read, because it uses another logic by combing the first two column. You want to have it in a more grafical way. Something like a WBS structure of a project like this

1

1.1

1.1.2

1.2

2..

Got it?

How important is this to you? Because this may need some deeeeeep thinking.

If this post helps or solves your problem, please mark it as solution.
Kudos are nice to - thanks
Have fun

Jimmy

 

 

dobregon
Impactful Individual
Impactful Individual

I have solved some minutes ago, doing this, it is not perfect because i dont want to create a function, table function and then take the data but.. for now it is solved. That i did

1. Create a Function

let
ReplaceAll = (InputTable as table, ColumnName as text, ReplacementTable as table, optional StartRow as number) =>
let
ActualRow = if (StartRow =null) then 0 else StartRow,
result = Table.ReplaceValue(InputTable, ReplacementTable{ActualRow}[ID], ReplacementTable{ActualRow}[Order] ,Replacer.ReplaceText, {ColumnName}),

NextRow = ActualRow + 1,

OutputTable = if NextRow > (Table.RowCount(ReplacementTable)-1)
then result
else
@ReplaceAll(result, ColumnName, ReplacementTable, NextRow)
in
OutputTable
in
ReplaceAll


2. Apply the function --> Create a new table with Path replaced values

Using this function I have created another table with the Path translated to what i want 

3. Take the column to my original table
I have created a column that takes the column values from my 2nd table where id = id

 



Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Hello @dobregon 

 

It Seems that you feed to the function a lookup table, that you prepared on Excel I suppose to change it one by one. However this could be accomplished also by a merge. Important is that you have a found solution.

However I like the recursive function to work through a table. Maybe it comes in handy one time

 

Bye

Jimmy

Hi @dobregon ,
How do you expect to arrive at the last two values?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors