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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.