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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Nicks612
Helper I
Helper I

how to make conditional column using two tables with reference to another table

I have two tables: table A and table B as shown below.

I want to make a conditional column in Table A with reference to Table B which contains OK and Nok data taking reference from Table B.

Table A contains:

 

Sr.NoDBKey
12345620230503092547
12345620230503084725
12345620230503070939
23567820230508100137
13245620230524172714
132456

20230527141557

16547820230514120545
765432

20230507130646

76543220230507131046

 

Table B contains:

 

Sr.NoDBKeyStatus
12345620230503084725Nok
23567820230508100137Ok
13245620230527141557Nok
76543220230507131046Nok

 

Result table A be like:

 

 

Sr.NoDBKeyNew Status
12345620230503092547Nok
12345620230503084725Nok
12345620230503070939Nok
23567820230508100137Ok
13245620230524172714Nok
13245620230527141557Nok
16547820230514120545 
76543220230507130646Nok
76543220230507131046Nok

 

 

Can anyone help me out with this problem? I have tried with the DAX lookup formula and succeeded but need to do it with the power query editor.

1 ACCEPTED SOLUTION

Hi @Nicks612 ,

Please try using merge query

vcgaomsft_1-1700735553096.png

and then transform the New Status column.

vcgaomsft_0-1700735508531.png

In the simulated data, there will be the case of matching to more than one status, here I assume that there is "OK" in the status to return "OK", otherwise return "NG".

vcgaomsft_2-1700735612407.png
Please check the pbix file.

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

5 REPLIES 5
Nicks612
Helper I
Helper I

Hello guys,

@tackytechtom  and @AlienSx 

sorry for the inconvenience!! there is some change in the previous data query. Please find the updated doubt.

 

I have two tables: table A and table B as shown below.

I want to make a conditional column in Table B with reference to Table A which contains OK and Nok data.

Table A contains:

 

Sr.NoStatusDBKey
123456OK20230503092547
123456NG20230503084725
123456OK20230503070939
235678NG20230508100137
132456NG20230524172714
132456OK20230527141557
165478OK20230514120545
765432NG20230507130646
765432NG20230507131046

 

Table B contains:

Sr.NoDBKey
12345620230503084725
23567820230508100137
13245620230527141557
76543220230507131046

 

Result table B be like:

 

Sr.NoDBKeyNew Status
12345620230503084725NG
23567820230508100137NG
13245620230527141557OK
76543220230507131046NG

 

Can you help me out with this problem? I have tried with the DAX lookup formula and succeeded but need to do it with the power query editor.

Hi @Nicks612 ,

Please try using merge query

vcgaomsft_1-1700735553096.png

and then transform the New Status column.

vcgaomsft_0-1700735508531.png

In the simulated data, there will be the case of matching to more than one status, here I assume that there is "OK" in the status to return "OK", otherwise return "NG".

vcgaomsft_2-1700735612407.png
Please check the pbix file.

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

Thanks a lot for the prompt response!

AlienSx
Super User
Super User

@Nicks612 

status_rec = Record.FromList(tblB[Status], List.Transform(tblB[Sr.No], Text.From)),
add_col = Table.AddColumn(tblA, "New Status", each Record.FieldOrDefault(status_rec, Text.From([Sr.No])))
tackytechtom
Super User
Super User

Hi @Nicks612 ,

 

How about this:

tackytechtom_0-1699711013322.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc47EoQwDAPQu6SmkCV/krMw3P8ahF1mQgGt30jWvjejPLJtjaAQEAbDqx3bm3UvxocVhsbPqMjqy7oBprtTfOboVizzV5t3i7hzOVetzilE+H9LTRPXvzIhPb/McNlxAg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Sr.No = _t, DBKey = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sr.No", Int64.Type}, {"DBKey", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Sr.No"}, TableB, {"Sr.No"}, "TableB", JoinKind.LeftOuter),
    #"Expanded TableB" = Table.ExpandTableColumn(#"Merged Queries", "TableB", {"Status"}, {"New Status"})
in
    #"Expanded TableB"

 

The trick is to use the merge function:

tackytechtom_2-1699711202833.png

 

let me know if this helps you 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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