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
toum
Helper II
Helper II

Power Query calculated column

Hello all, please, I need your help with Power Query. I need to create a new column that follows this logic:

 

toum_0-1702490577557.png

 

1 ACCEPTED SOLUTION

Hi @toum ,

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQKhWJ1oJScgwxGMQTxnIMsJJuWCzHFDUecBZLnBpIKBjCAwBvG8gaxgsFQsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Home = _t, Destination = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Home", type text}, {"Destination", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Home"}, #"Changed Type", {"Name"}, "Added Custom", JoinKind.LeftOuter),
#"Expanded Added Custom2" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"Destination"}, {"Added Custom.Destination"}),
#"Added Custom" = Table.AddColumn(#"Expanded Added Custom2", "NewColumn", each
if [Destination] = "" then [Added Custom.Destination]
else [Destination]),
#"Replaced Value" = Table.ReplaceValue(#"Added Custom",null, each [Name],Replacer.ReplaceValue,{"NewColumn"}),
#"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Added Custom.Destination"}),
#"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Name", Order.Ascending}})
in
#"Sorted Rows"

 

Do not forget to mark the answer as a solution so others can easily spot the answer!

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

3 REPLIES 3
tackytechtom
Super User
Super User

Hi @toum ,

 

How about this:

tackytechtom_0-1702495690535.png

 

 

Here the code that you can paste into the advanced editor. Feel free to check out the steps on the right hand side as well 🙂

 

tackytechtom_1-1702495779718.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQKhWJ1oJScgwxGMQTxnIMsJJuWCzHFDUecBZLnBpIKBjCAwBvG8gaxgsFQsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Home = _t, Destination = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Home", type text}, {"Destination", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Home"}, #"Changed Type", {"Name"}, "Added Custom", JoinKind.LeftOuter),
    #"Expanded Added Custom2" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"Destination"}, {"Added Custom.Destination"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Added Custom2", "NewColumn", each if [Destination] = "" then [Added Custom.Destination] else [Destination]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Added Custom.Destination"}),
    #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Name", Order.Ascending}})
in
    #"Sorted Rows"

 

Hope this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Thank you a lot for your help, that's what I needed but plz another thing for the row1 the NewColumn should be A. (if destination is empty and Name=Home or Home is empty the newColumn should = Name).  

Hi @toum ,

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQKhWJ1oJScgwxGMQTxnIMsJJuWCzHFDUecBZLnBpIKBjCAwBvG8gaxgsFQsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Home = _t, Destination = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Home", type text}, {"Destination", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Home"}, #"Changed Type", {"Name"}, "Added Custom", JoinKind.LeftOuter),
#"Expanded Added Custom2" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"Destination"}, {"Added Custom.Destination"}),
#"Added Custom" = Table.AddColumn(#"Expanded Added Custom2", "NewColumn", each
if [Destination] = "" then [Added Custom.Destination]
else [Destination]),
#"Replaced Value" = Table.ReplaceValue(#"Added Custom",null, each [Name],Replacer.ReplaceValue,{"NewColumn"}),
#"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Added Custom.Destination"}),
#"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Name", Order.Ascending}})
in
#"Sorted Rows"

 

Do not forget to mark the answer as a solution so others can easily spot the answer!

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

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.