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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
chrisqqq123
New Member

Assigning values in one column based on values in two other columns

Hi all, ...I have been using Power Query for creating enormous Excel tables from multiple files in a folder, and getting better at manipulating the data. I have run across a problem I have not been able to solve. I have a column with customer names (it also includes other data like numbers), and I need to apply those customer names to numerous cells based on other columns. For example, "Ed" is the customer for "town." How can I apply the customer "Ed" to all the rows that are labeled"town"? (There are hundreds of "Name" values) The second table in the picture is the table I'd like to get to, and I'm trying to use Advanced Editor in Power Query to get this result. I will eventually keep Column B, as I need to retain the number values.

 

table1.jpg

 

 

So how can I add the customer names to the appropriate values for the "Name" column?

Thank you!

 

 

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @chrisqqq123,

 

Create a new custom column with the following code:

if [ColumnB] = "customer" then [Customer] else null

Then just sort by Name and by customer name.

 

Finally just make the fill down and you will get all the values you need.

 

filll.gif

 

See below the code I used:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKskvz1PSUQKi9KLUvDylWB24WHJpcUl+bmoRkOmagixhAtIA4idnllQC2UbmFkAyrzQnB1kUSXtwYi6yDEx7cUliSSqQY2gOJMxMUcSQdZckJleiSIINiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, ColumnB = _t, Customer = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"ColumnB", type text}, {"Customer", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Customer Name", each if [ColumnB] = "customer" then [Customer] else null),
    #"Sorted Rows" = Table.Sort(#"Added Custom",{{"Name", Order.Ascending}, {"Customer Name", Order.Descending}}),
    #"Filled Down" = Table.FillDown(#"Sorted Rows",{"Customer Name"})
in
    #"Filled Down"

Be carefull that this is assuming that your customer is always the same for the column name if you have more than one customer name for city you can have an issue since the name may not stay correct.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @chrisqqq123,

 

Create a new custom column with the following code:

if [ColumnB] = "customer" then [Customer] else null

Then just sort by Name and by customer name.

 

Finally just make the fill down and you will get all the values you need.

 

filll.gif

 

See below the code I used:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKskvz1PSUQKi9KLUvDylWB24WHJpcUl+bmoRkOmagixhAtIA4idnllQC2UbmFkAyrzQnB1kUSXtwYi6yDEx7cUliSSqQY2gOJMxMUcSQdZckJleiSIINiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, ColumnB = _t, Customer = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"ColumnB", type text}, {"Customer", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Customer Name", each if [ColumnB] = "customer" then [Customer] else null),
    #"Sorted Rows" = Table.Sort(#"Added Custom",{{"Name", Order.Ascending}, {"Customer Name", Order.Descending}}),
    #"Filled Down" = Table.FillDown(#"Sorted Rows",{"Customer Name"})
in
    #"Filled Down"

Be carefull that this is assuming that your customer is always the same for the column name if you have more than one customer name for city you can have an issue since the name may not stay correct.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.