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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
smacsween
Frequent Visitor

Conditional merge columns

i am trying to merge columns based on an IF statement and ISBLANK.  If I have Country name in Table1, use that value, if not, use the Country value from Table2.

 

I can't see how to do this, I have created a measure but it does not give any results

 

OfficeCombined =
IF (
isblank(SELECTEDVALUE ( 'Table1'[Country] ) ),
SELECTEDVALUE ( Table2[Country] ),
SELECTEDVALUE ( 'Table1'[Country] )
)
 
What am I doing wrong? it's driving me crazy, seems so simple but I can't figure out DAX
1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @smacsween ,

 

Just try this:

NewTable =
DISTINCT (
    UNION ( DISTINCT ( Table1[Country] ), DISTINCT ( Table2[Country] ) )
)

 

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

View solution in original post

6 REPLIES 6
smacsween
Frequent Visitor

What I am trying to do is create a new text column:

 

Let's see if I can describe it differently.  If the text already exists in a column from Table 1, use that. If that column in Table 1 is null or blank, instead take the text from the relevant column in Table 2. 

 

The Union function gives me both together, and I end up with different rows but containing identical data.  I only need one or the other because the field will be present in at least one of the columns, maybe both.

Icey
Community Support
Community Support

Hi @smacsween ,

 

Just try this:

NewTable =
DISTINCT (
    UNION ( DISTINCT ( Table1[Country] ), DISTINCT ( Table2[Country] ) )
)

 

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

Icey
Community Support
Community Support

Hi @smacsween ,

 

SELECTEDVALUE('Table1'[Country]) will only return the countries included in Table1, and will not compare the countries in Table1 and Table2 to see if they are included. Same as SELECTEDVALUE('Table2'[Country]).

So, if "Country 1" is only contained in Table2, SELECTEDVALUE('Table1'[Country]) will not return blank for it.

 

It is suggested to create a table like below and create relationships among them:

NewTable =
UNION ( DISTINCT ( Table1[Country] ), DISTINCT ( Table2[Country] ) )

table.JPGre.JPG

 

 

Best regards

Icey

 

If this post helps, then consider Accepting it as the solution to help other members find it faster.

smacsween
Frequent Visitor

It's two text columns I want to merge so actually a measure is probably not the thing I should have tried, it should just be a new column.  What would be the corresponding formula for a text merge based on that scenario?

It's a calculated column?  If so, take off the MIN( ) for whichever table you are putting it on.  For example, if adding the column to Table 2,

 

OfficeCombined =
IF (
isblank(MIN ( 'Table1'[Country] ) ),
Table2[Country] ,
MIN ( 'Table1'[Country] )
)
 
Regards,
Pat




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


mahoneypat
Microsoft Employee
Microsoft Employee

You said this is a measure, so I assume you are using it in a table visual.  What is the relationhip between Table1 and Table2.  You could try this instead, but will depend on the relatinship.

 

OfficeCombined =
IF (
isblank(MIN ( 'Table1'[Country] ) ),
MIN ( Table2[Country] ),
MIN ( 'Table1'[Country] )
)
 
Regards,
Pat




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors