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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Conditional column selecting column from other table

Hello all.

I need a help.

 

I have two tables:

Table A with customer by entity name

Table B with customer by entity name and short name

 

How can I add a conditional column in Table A selecting a column from Table B (entity name) with output from Table B (short name)? 

 

I don't have all customer in Table B, so I need also a condition that null returns the customer (entity name) from Table A.

 

Capture.PNG

 

Thanks!

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous 

Got it! So you can merge the tables with a LEFT JOIN. Then you can create a new conditional column with the format:

IF [new column] = null THEN output=Column1, ELSE [new column]

 

Capture.PNG]

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

@Anonymous 

You're going to want to have a column with a unique ID that you can use to join Table A and Table B. Then you can select "Merge Queries" in the query editor, match on the unique ID, and make sure that it is the Join Kind "Left Outer (all from first, matching from second)." That way, since Table B doesn't have all of the entries that Table A has, the short name column entries that don't have a match will be replaced with a null in your new, merged table.

Is that what you want to do?

Anonymous
Not applicable

Hi @Anonymous 

 

I also want to change the null that I will have in the merged table by the Customer name (entity name) from Table A.

Anonymous
Not applicable

@Anonymous 

So do you have some customers in Table B that are not in Table A? If so, since you are using a left join, those customers would not appear in your merged table.

Anonymous
Not applicable

@Anonymous 

But I need to have a complete table by short name or entity name.

Anonymous
Not applicable

@Anonymous 

I think I am confused as to what your two tables contain. Does Table A overlap with Table B? I know that there are entries in Table A that are not in Table B but are there also entries in Table B that are not in Table A?

Anonymous
Not applicable

Hi @Anonymous 

I think now will be easier to understand. 

 

Table A Table B  Output
Customer CustomerShort Name Short Name
Power BI AS Power BI ASPower BI Power BI
Power BI Ltd Power BI LtdPower BI Power BI
Power BI Desktop AS Power BI Desktop ASPower BI Power BI
Power BI Service AS Power BI Service ASPower BI Power BI
Micro AS Micro ASMicro Micro
Micro Soft Ltd Micro Soft LtdMicro Micro
Solutions AS    Solutions AS
Mobile Ltd    Mobile Ltd
Consulting Ltd    Consulting Ltd
Anonymous
Not applicable

@Anonymous 

Got it! So you can merge the tables with a LEFT JOIN. Then you can create a new conditional column with the format:

IF [new column] = null THEN output=Column1, ELSE [new column]

 

Capture.PNG]

Anonymous
Not applicable

Thanks, @Anonymous 

Last doubt: is it possible to have the merged column (Table2.Column2) in Table A? I am wondering if I can avoid one more table. 

Anonymous
Not applicable

@Anonymous 

I think the only way to do that without merging queries would be to add a conditional column straightaway from Table A. This would automatically give customers by entity name a short name if it included something like "power bi" or "microsoft" and return the regular entity name if it has no short name.

Capture2.PNG

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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