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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
l1800turbo
Regular Visitor

Adding column values from other table for empty cells

Hello,

 

I'm building a table where I fetch data from an SQL database. In this table some values are empty (=null).

For these empty cells I want to add values from another table, but they should only be inserted on empty cells.

 

My current approach after hours was iterating over all columns that can contain cells with possible null values to be replaced and running a small function. In the function I replace all empty values with the values of the other table.

 

This is my current idea, it's working, but terribly slow and takes minutes to process.

 

 

Replacer = (TableRef as table, ColumnName) =>
        Table.ReplaceValue(
        TableRef,
        each null,
        each
            let
                currentMatNr = [MatNr]
            in
                List.First(
                    Table.Column(
                        Table.SelectRows(Simulation_Database_TSA_tmp, each [MatNr] = currentMatNr),
                        ColumnName
                    )
                ),
        Replacer.ReplaceValue,
        {ColumnName}
    ),

TSA_Columns = {"H", "TAMAX", "TJMAX", "RTHJA"},

TSA_DB_Add3=List.Accumulate(TSA_Columns, TSA_DB_Add2, (param_seed, param_list)=>Replacer(param_seed, param_list)),

 

 

I'm quite sure there are much better ways, maybe someone has an idea for this.

 

Thanks!

3 REPLIES 3
l1800turbo
Regular Visitor

Hello,

thank you for the answers!

@BA_Pete : Unfortunately one is SQL and the other table is Excel from a Sharepoint. Otherwise a direct SQL Query would be the best, for sure!

 

@wdx223_Daniel : Could you explain the function a little bit? MatNr is a unique column.

I tried your proposal, but I got an error, especially the part

a{[MatNr=[MatNr]]}? ??[]

 is unclear to me. PowerQuery marks a as unknown, I don't know this kind of condition to look up the meaning. At first it looked like a short IF like in C, but I couldn't find anything similar, so far.

 

Thank you!

wdx223_Daniel
Super User
Super User

if the table of Simulation_Database_TSA_tmp is unique in the column of MatNr, then

TSA_DB_Add3=let a=Table.Buffer(Simulation_Database_TSA_tmp) in Table.FromRecords(Table.TrandformRows(TSA_DB_Add2,each Record.TransformFields(_,List.Transform(TSA_Columns,(x)=>{x, each Record.FieldOrDefault(a{[MatNr=[MatNr]]}? ??[],x,null)}),2)))

 

if not, then

TSA_DB_Add3=let a=Table.Buffer(Table.Group(Simulation_Database_TSA_tmp,"MatNr",{"n",each _{0}})) in Table.FromRecords(Table.TrandformRows(TSA_DB_Add2,each Record.TransformFields(_,List.Transform(TSA_Columns,(x)=>{x, each Record.FieldOrDefault(a{[MatNr=[MatNr]]}?[n]? ??[],x,null)}),2)))

BA_Pete
Super User
Super User

Hi @l1800turbo ,

 

Is the table that you want to get the replacement values from on the same SQL server/database as the one with the nulls? If it is then it would be significantly faster to just merge the two tables and create new conditional columns as

if [originalTableCol] = null then [otherTableCol] else [originalTableCol]

This would fold back to the server so would be processed in a heartbeat.

 

Even if you can't get it to fold, I'm thinking this method could be quicker than your custom function anyway.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.