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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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
Top Kudoed Authors