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
Anonymous
Not applicable

Conditional import from Excel

Hi,

 

When importing data from an excel file, I need to substitute some values with alternative values form another column. Is there a possibility in PowerBI import to do this? 

1 ACCEPTED SOLUTION

@Anonymous ,

 

Ok. So there's two (similar) ways to do this:

 

1) Create a new column (easy):

Add a new custom column with the following code:

 

if [End Customer] = "Not Applicable" then [Purchasing channel] else [End Customer]

 

 

---OR---

 

2) Replace N/A values within the existing column (intermediate):

Find a 'Not Applicable' value in your [End Customer] column, right-click and hit Replace Values.

In the dialog, add any text as the Replace With value, then hit OK:

BA_Pete_1-1636723835955.png

You will see in your formula bar that it has generated this code:

 

= Table.ReplaceValue(previousStep,"Not Applicable","abc",Replacer.ReplaceText,{"End Customer"})

 

Now replace the "abc" section with 'each [Purchasing channel]'. It should look like this:

 

= Table.ReplaceValue(previousStep,"Not Applicable", each [Purchasing channel], Replacer.ReplaceText,{"End Customer"})

 

This gives the following output:

BA_Pete_2-1636724054357.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

3 REPLIES 3
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

This isn't something that can be done during the data import per se, but it can certainly be done before the data is applied to the data model for reporting.

 

The data flow in Power BI Desktop in its most basic form is:

 

Data Source (Excel in your case) >> Power Query (do transformations) >> Data Model (define relationships) >> Report (write measures and visualise data).

 

What you're describing would be a transformation step that would be done in Power Query.

 

If you need help doing this, post an example of your data in this thread with a detailed description of what you want done and expected end result.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

Hi, Pete, pls check this sample data:

 

1. Incoming data shows that some POSs maybe resold to an end-customer companies:

 

item#Purchasing channelEnd Customer Sales volume
1Star Inc.Not Applicable100
2Cube Inc.PPM Co.20
3Alliance Co.ABC Inc.500
4Star Inc.PPM Co.50
5Star Inc.Not Applicable45
6Cube Inc.Not Applicable20
7Alliance Co.ABC Inc.500
8Alliance Co.ABC Inc.20
9Alliance Co.PPM Co.300
10Star Inc.Not Applicable45

 

2. after processing the highlighted items in red has to be substituted by the items in 2d column:

 

item#Purchasing channelEnd Customer Sales volume
1Star Inc.Star Inc.100
2Cube Inc.PPM Co.20
3Alliance Co.ABC Inc.500
4Star Inc.PPM Co.50
5Star Inc.Star Inc.45
6Cube Inc.Cube Inc.20
7Alliance Co.ABC Inc.500
8Alliance Co.ABC Inc.20
9Alliance Co.PPM Co.300
10Star Inc.Star Inc.45

@Anonymous ,

 

Ok. So there's two (similar) ways to do this:

 

1) Create a new column (easy):

Add a new custom column with the following code:

 

if [End Customer] = "Not Applicable" then [Purchasing channel] else [End Customer]

 

 

---OR---

 

2) Replace N/A values within the existing column (intermediate):

Find a 'Not Applicable' value in your [End Customer] column, right-click and hit Replace Values.

In the dialog, add any text as the Replace With value, then hit OK:

BA_Pete_1-1636723835955.png

You will see in your formula bar that it has generated this code:

 

= Table.ReplaceValue(previousStep,"Not Applicable","abc",Replacer.ReplaceText,{"End Customer"})

 

Now replace the "abc" section with 'each [Purchasing channel]'. It should look like this:

 

= Table.ReplaceValue(previousStep,"Not Applicable", each [Purchasing channel], Replacer.ReplaceText,{"End Customer"})

 

This gives the following output:

BA_Pete_2-1636724054357.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




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