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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Updating selective columns in and appending new rows to Historical Table from Update Table

I have 2 tables, #"Lead Data1" and #"Enrolment Data", with ~300k and ~16k rows respectively with key (Lead Number). I am using a separate query to pull #"Enrolment Data".
I want to update the #"Lead Data1" columns {"Created On", "Course", "Program", "Business"} from the #"Enrolment Data", retaining the other columns.
If any key (Lead Number) in #"Enrolment Data" is not found in #"Lead Data1", those records need to be appended to it.

 

I tried the below code:

let

Source = Excel.Workbook(File.Contents("xxx.xlsb"), null, true),

#"Lead Data1" = Source{[Name="Lead Data"]}[Data],

#"Promoted Headers" = Table.PromoteHeaders(#"Lead Data1", [PromoteAllScalars=true]),

#"Removed Other Columns" = Table.SelectColumns(#"Promoted Headers",{"Created On", "Owner", "Lead Number", "Source", "Source type", "TL", "Course", "Program", "Business"}),

Here I remove all unnecessary columns, these are the ones I need in my output from combining #"Lead Data1" and #"Enrolment Data". I will use #"Removed Other Columns" table again to append non-matched items.

 

#"Removed Other Columns1" = Table.SelectColumns(#"Removed Other Columns",{"Owner", "Lead Number", "Source", "Source type", "TL"}),

I only keep columns I need to merge to #"Enrolment Data" (which don't have these)

 

#"Merged Queries" = Table.Join(#"Removed Other Columns1", {"Lead Number"}, #"Enrolment Data", {"Lead Number"}, JoinKind.RightOuter, 2),

I am merging with #"Enrolment Data" and not the other way around because it has much lower number of rows (if that makes a difference). This would give me the "updated" rows, including those with keys not matching #"Lead Data1".

 

#"Rows to Remove" = Table.Column(#"Merged Queries","Lead Number"),

Once merged, I select the list of matched keys (updated rows) in #"Enrolment Data".

 

#"Selected Rows" = Table.RemoveMatchingRows(#"Removed Other Columns", each List.Contains(#"Rows to Remove",[#"Lead Number"])),

I remove those rows from #"Lead Data1" (giving "non-updated" rows)

 

#"Appended Queries" = Table.Combine({#"Merged Queries", #"Selected Rows"})

I append the "Updated" and "Non-Updated" rows.

 

in #"Appended Queries"

 

However, the query throws an error of "Data Source not found" - I think this might be because I am referencing #"Removed Other Columns" table wrong. Is there any way around it, or my approach itself is faulty? If so, any solution will be highly appreciated.

 

Lead Data        
Created On "Owner" "Lead Number" "Source" "Source type" "TL" "Course" "Program" "Business"
01/01/2024A1123B1C1D1E1F1G1
02/01/2024A2124B2C2D2E2F2G2
03/01/2024A3125B3C3D3E3F3G3
04/01/2024A4126B4C4D4E4F4G4
05/01/2024A5127B5C5D5E5F5G5
06/01/2024A6128B6C6D6E6F6G6
         
Enrolment Data        
Created On "Lead Number" "Course" "Program" "Business"    
03/01/2024125E7F7G7    
04/01/2024126E8F8G8    
07/01/2024ABCE9F9G9    
         
Output        
Created On "Owner" "Lead Number" "Source" "Source type" "TL" "Course" "Program" "Business"
01/01/2024A1123B1C1D1E1F1G1
02/01/2024A2124B2C2D2E2F2G2
03/01/2024A3125B3C3D3E7F7G7
04/01/2024A4126B4C4D4E8F8G8
05/01/2024A5127B5C5D5E5F5G5
06/01/2024A6128B6C6D6E6F6G6
07/01/2024nullABCnullnullnullE9F9G9
2 REPLIES 2
Sahir_Maharaj
Super User
Super User

Hello @Anonymous,

 

Can you please try this streamlined version of your approach:

let
    SourceLeadData = Excel.Workbook(File.Contents("xxx.xlsb"), null, true),
    LeadData1 = SourceLeadData{[Name="Lead Data"]}[Data],
    PromotedHeadersLead = Table.PromoteHeaders(LeadData1, [PromoteAllScalars=true]),

    SourceEnrolmentData = Excel.Workbook(File.Contents("yyy.xlsb"), null, true),
    EnrolmentData = SourceEnrolmentData{[Name="Enrolment Data"]}[Data],
    PromotedHeadersEnrolment = Table.PromoteHeaders(EnrolmentData, [PromoteAllScalars=true]),

    MergedQueries = Table.Join(PromotedHeadersLead, "Lead Number", PromotedHeadersEnrolment, "Lead Number", JoinKind.FullOuter),

    CustomUpdated = Table.AddColumn(MergedQueries, "Custom Created On", each if [Created On.1] = null then [Created On] else [Created On.1]),

    RemovedIntermediateColumns = Table.RemoveColumns(CustomUpdated,{"Created On", "Created On.1", "Course", "Course.1", "Program", "Program.1", "Business", "Business.1"}),

    RenamedColumns = Table.RenameColumns(RemovedIntermediateColumns, {{"Custom Created On", "Created On"}})
    // Repeat the renaming for other custom columns as needed

in
    RenamedColumns

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Anonymous
Not applicable

I have tried this solution, and it works, but feels very inefficient as the operations have to done on all 300k rows. It takes a really long time, and further increases if I need to update more columns (I removed a few here for simplicity). I was hoping there was a better and efficient way to perform the same operation using merge and append combo.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors