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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
klehar
Helper V
Helper V

Conditional Columns to replace nulls

Hi,

 

I have  2 Geo columns coming from 2 different tables. I want to create a 3rd column such that:

if Table1.Geo is blank then Table2.Geo, else Table1.Geo

Table1.GeoTable2.GeoFinal Geo
Europe Europe
 AsiaAsia
nullnull

null

 

 

However, I dont think replacing blank values in the Final Geo column using such conditions is a good practise.

I say this becuase in reality, I have 50 other columns where I need to do the same thing.

I think this is not scalable.

is there an easier way out to this problem?

 

I need the solution in M Code

6 REPLIES 6
lbendlin
Super User
Super User

Please provide some more sample data (ie more columns) and show the expected outcome.

Sample data is client confidential

But the intuituion is simple

 

Just consider that I have 50 columns like the one I mentioned above.

For these 50 columns i dont want to write conditional statements for each

Whats the easy way out?

 

Here is another example.

Orange columns are output columns

Geo 1Geo 2Country 1Country 2Final GeoFinal Country
AsiaAsiaIndiaIndiaAsiaIndia
nullEuropenullUSEuropeUS
Anonymous
Not applicable

HI @klehar,

How did these table records mapping? Can you please share some more detailed information to help us clarify your scenario and test to coding formula?

How to Get Your Question Answered Quickly

Regards,

Xiaoxin Sheng

@Anonymous Geo field has come from 2 tables. Both columns contain some nulls. So i created a new column that can replace nulls if atleast one column contains a non null value. Like Geo I have 40 other columns that have the same case.So I was thinking of a smarter solution instead of creating 40 conditional columns

Anonymous
Not applicable

Hi @klehar,

This is the reason we required more detailed information.
If these tables have relationship keys to mapping different records, you can extract these keys to create a bridge table to link these tables and add calculated fields with replaced geo values.
After these steps, you can directly invoke this replaced bridge table field to get results.
Regards,

Xiaoxin Sheng

Mentioning "confidential" is one of the inhibitors of getting help. Providing incorrect sample data is another.

Please reconsider.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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