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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
lovetolearn
New Member

How do I combine the data of two columns and prioritise data from one?

I have data spanning over 4 years from a lead generation system. At some point a data field called "State" was used and later they started using another field called "Province".

What I have - two columns with some data, some blank fields and sometimes a value in both columns.

what i have.png

I would like to create a third column where I combine the data from the first two columns, but in instances where both columns have data, I want the data from "Province" to be in the Combined column and discard the value from "State".
what I want.png

 

I know how to combine data, but I don't know how to end up with only the single values when there are two values per row.

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @lovetolearn ,

 

You can try the formula like below:

Col = 
IF (
    'Table'[State] = BLANK ()
        && 'Table'[Provice] = BLANK (),
    BLANK (),
    IF (
        'Table'[Provice] <> BLANK ()
            && 'Table'[State] <> BLANK (),
        'Table'[State],
        IF (
            'Table'[State] = BLANK ()
                && 'Table'[Provice] <> BLANK (),
            'Table'[Provice],
            'Table'[State]
        )
    )
)

vhenrykmstf_0-1648461659982.png

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-henryk-mstf
Community Support
Community Support

Hi @lovetolearn ,

 

You can try the formula like below:

Col = 
IF (
    'Table'[State] = BLANK ()
        && 'Table'[Provice] = BLANK (),
    BLANK (),
    IF (
        'Table'[Provice] <> BLANK ()
            && 'Table'[State] <> BLANK (),
        'Table'[State],
        IF (
            'Table'[State] = BLANK ()
                && 'Table'[Provice] <> BLANK (),
            'Table'[Provice],
            'Table'[State]
        )
    )
)

vhenrykmstf_0-1648461659982.png

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for this solution, it worked perfectly.

Do you know how I can accomplish this with an M Query so I can add it as an automatic step whenever I import updated data?

 

lovetolearn_0-1655008582093.png

 

amitchandak
Super User
Super User

@lovetolearn ,

 

a new column in dax = coalesce([State], [province] )

 

In power query

if [State] = null then [province] else [province]

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandakThanks for the reply. The logic seems right but it doesn't quite work. This is my result:

 

Screenshot 2022-03-22 224958.png

 

Screenshot 2022-03-22 225137.png

 

Screenshot 2022-03-22 225200.png

Helpful resources

Announcements
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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors