cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
adni85
Regular Visitor

Replace N/A value with non-null value in same column

Hi

I am quite new to the power BI world and stuck with this issue.

20220114_155144.jpg

 

So as shown in table below, I have few N/A values in 'City' column. I want to replace N/A with the value based on the customer column.

 

Like, if customer 'EFG' is shown Toronto in above or below cell than the 'N/A' could replaced with Toronto and in the case of customer 'ABC' N/A to be replaced with Vancouver.

 

TIA

1 ACCEPTED SOLUTION
Eyelyn9
Community Support
Community Support

Hi @adni85 ,

 

Below is the full M syntax that you could paste in Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRMtQ31DcyMDICMsMS85LzS8tSi5RidaKVXN3cUaVD8ovy80rywZIRkVGokn6p5ZX5RdkoOo3gkvqOKBLG2IyEOccYXRfMLmNsdgWGu2LXBZMwgUk4pWZmZealK8XGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, Dates = _t, City = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Dates", type date}, {"City", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","N/A",null,Replacer.ReplaceValue,{"City"}),
    #"Sorted Rows" = Table.Sort(#"Replaced Value",{{"City", Order.Descending}}),
    #"Group" = Table.Group(#"Sorted Rows", {"Customer"}, {{"All_Rows", each Table.FillDown(_,{"City"}), type table}}),     
    #"Expanded All_Rows" = Table.ExpandTableColumn(Group, "All_Rows", {"Dates", "City"}, {"Dates", "City"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded All_Rows",{{"Dates", type date}})
in
    #"Changed Type1"

 

Eyelyn9_1-1642486870493.png

 

 

Best Regards,
Eyelyn Qin
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

3 REPLIES 3
Eyelyn9
Community Support
Community Support

Hi @adni85 ,

 

Below is the full M syntax that you could paste in Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRMtQ31DcyMDICMsMS85LzS8tSi5RidaKVXN3cUaVD8ovy80rywZIRkVGokn6p5ZX5RdkoOo3gkvqOKBLG2IyEOccYXRfMLmNsdgWGu2LXBZMwgUk4pWZmZealK8XGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, Dates = _t, City = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Dates", type date}, {"City", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","N/A",null,Replacer.ReplaceValue,{"City"}),
    #"Sorted Rows" = Table.Sort(#"Replaced Value",{{"City", Order.Descending}}),
    #"Group" = Table.Group(#"Sorted Rows", {"Customer"}, {{"All_Rows", each Table.FillDown(_,{"City"}), type table}}),     
    #"Expanded All_Rows" = Table.ExpandTableColumn(Group, "All_Rows", {"Dates", "City"}, {"Dates", "City"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded All_Rows",{{"Dates", type date}})
in
    #"Changed Type1"

 

Eyelyn9_1-1642486870493.png

 

 

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

AlexisOlson
Super User
Super User

Is a Customer always associated with only a single City? If not, how do you choose which city to replace N/A with?

Yes in this case customer is associated to one particular city.

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May 23 2022 epsiode 5 without aka link.jpg

The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt talks about the importance of Data Modeling.

Power BI Dev Camp Session 22 with aka link 768x460.jpg

Check it out!

Mark your calendars and join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!