March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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!
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!
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)))
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
Proud to be a Datanaut!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
21 | |
16 | |
13 | |
12 | |
9 |
User | Count |
---|---|
34 | |
31 | |
20 | |
19 | |
17 |