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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
norocdinu
Frequent Visitor

Looping between 2 rows and create a 3rd row

Please help.

I have a situation where I have two ID columns. first one is the Initial ID second is the new ID. Over time the new ID wil be moved in initial ID and be once again replaced with a new one. This may happen multipla times. I need to iterate between theese 2 columns until I get the final ID. As per example below the loop must finish when ID = New ID
Screenshot 2022-12-02 155030.png
if Id<>New ID then remember New ID  and find in column ID and compare it with New ID again... do this until Id=New ID


1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @norocdinu ,

According to your description, It's easy to do in DAX with PATH function, create a calculated column.

Column =
PATHITEM ( PATH ( 'Table'[ID], 'Table'[New ID] ), 1, TEXT )

I shuffled the data order of the sample, get correct result:

vkalyjmsft_0-1670230178277.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yanjiang-msft
Community Support
Community Support

Hi @norocdinu ,

According to your description, It's easy to do in DAX with PATH function, create a calculated column.

Column =
PATHITEM ( PATH ( 'Table'[ID], 'Table'[New ID] ), 1, TEXT )

I shuffled the data order of the sample, get correct result:

vkalyjmsft_0-1670230178277.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you! This worked perfectly!

rohit_singh
Solution Sage
Solution Sage

Hi @norocdinu ,

You could try something like this. 
Please open a blank query--> Advanced editor-->Remove any existing code and copy and paste the below code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc3BDQAhCETRXjh7QECBWoj9t7EYjWFvk5dJfgQ4O4tDg85ILBNWi7e3knXSq2enSh6Qjt6d6gN19qN3/3XHBr6Ylpi+mJWYVV0f", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, NewID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"NewID", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "FinalID", each if [ID] = [NewID] then [NewID] else null),
    #"Filled Up" = Table.FillUp(#"Added Custom",{"FinalID"})
in
    #"Filled Up"

 

 

Input

rohit_singh_0-1669990619922.png

Output

rohit_singh_1-1669990649671.png

 

 

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos!

Thank you for your answer, but the problem is that data is not sorted like in my example, this is why I cannot use this solution. 
I am looking inot some Loop functions, but so far I couldn't find a suitable solution.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.