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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Arnoh
Helper III
Helper III

finding first record

Hi I have the following issue:

 

I have a table as below

 

 

idsource_id 
100  
101100 
102  
103102 
104101 
105104 

 

 

I want to find the first record of 

so the result should look like this

 

idsource_idfirst_id
100 100
101100100
102 102
103102102
104101100
105104100

 

Thanx for helping!

4 REPLIES 4
ThxAlot
Super User
Super User

Use recursive function in PQ

 

 

let
    Fx = (id, src) =>
    let pos = List.PositionOf(ID, src)
    in if pos > -1 then @Fx(ID{pos}, Src{pos}) else id,

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRUorVATENgUyQAIRnhJAwBksYQXkmYJ4hlGcK5pkoxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, source_id = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"source_id", Int64.Type}}),
    ID = #"Changed Type"[id], src=#"Changed Type"[source_id],
    
    Traced = Table.AddColumn(#"Changed Type", "Root", each fx([id], [source_id]))
in
    Traced

 

 

 

ThxAlot_0-1690367123941.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Hi Thanx for your reaction,

 

I can't get it working. I did try to copy your code in power query. 

Can you add extra information on how to create the recursive function in Power Query? 

 

Thanx 

Kev74
Frequent Visitor

Hi try it :

 

first_id = IF(ISBLANK(LOOKUPVALUE('Table'[id], 'Table'[id], 'Table'[source_id])), 'Table'[id], LOOKUPVALUE('Table'[id], 'Table'[id], 'Table'[source_id]))

Hi Thanx for your reaction.

But this is n't going to work. 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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