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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
uthall
Helper II
Helper II

New Column where it queries value in related table

Hello,

 

I have 2 related tables

 

I wish to add a new column to one of them which adds a defaul value based on the value of the related table.

 

i.e

Table1.newcolumn

if Table2.columnA = null, then new "New value" else "Another value"

 

In the custom table editor, it only provides columns from the table i am adding the colun to, and does nopt list the related colum,ns in the re,ated tables?

 

Any ideas?

 

Thnx

Jeff

 

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

Hi @uthall,

 

dkay84_PowerBI's point seems great, I'd like to share you a sample about use other table's value as the default value. (power query).

 

Below is the sample.

 

Formula:

 

    defultValue= List.First(Table.SelectRows(Table.SelectColumns(Source,"ColumnName"),each _ <> null)[ColumnName]),
    #"Replaced Value" = Table.ReplaceValue(#"Previous Steps",null,defultValue,Replacer.ReplaceValue,Table.ColumnNames(#"Previous Steps"))

 

 

Table:

Capture.PNG

 

Capture2.PNG

 

 

Result:

Capture3.PNG

 

 

Full query:

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\test.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet),

    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"Desc", type text}}),
    defultValue= List.First(Table.SelectRows(Table.SelectColumns(Sheet2,"Amount"),each _ <> null)[Amount]),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","Dsvl",defultValue,Replacer.ReplaceValue,Table.ColumnNames(#"Changed Type"))//devl is the value which need to replace
in
    #"Replaced Value"

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @uthall,

 

dkay84_PowerBI's point seems great, I'd like to share you a sample about use other table's value as the default value. (power query).

 

Below is the sample.

 

Formula:

 

    defultValue= List.First(Table.SelectRows(Table.SelectColumns(Source,"ColumnName"),each _ <> null)[ColumnName]),
    #"Replaced Value" = Table.ReplaceValue(#"Previous Steps",null,defultValue,Replacer.ReplaceValue,Table.ColumnNames(#"Previous Steps"))

 

 

Table:

Capture.PNG

 

Capture2.PNG

 

 

Result:

Capture3.PNG

 

 

Full query:

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\xxxx\Desktop\test.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet),

    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"ID", Int64.Type}, {"Desc", type text}}),
    defultValue= List.First(Table.SelectRows(Table.SelectColumns(Sheet2,"Amount"),each _ <> null)[Amount]),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","Dsvl",defultValue,Replacer.ReplaceValue,Table.ColumnNames(#"Changed Type"))//devl is the value which need to replace
in
    #"Replaced Value"

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

You can still refer to other tables/queries, they just aren't given in the list.  You have to tell the custom formula the table and column (and row number if necessary) that it should look at for your condition.  I believe the syntax will be #"Table"[Column]{row}

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.