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
Duffy789
New Member

Swapping cells values over in 2 colums

Hi, I have 2 columns and the data value needs to be swapped around, this is due to the source not been ideal, it is not possible to sort the source out.

 

See below what I woudl like is the the date under Tag_Zone_Org to be swapped over with the "1" under Tag_Date_Created_Org

I am pretty new to PowerBI so might need a very easy guide.

 

Thanks 

 

Duffy789_1-1689078788318.png

 

 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Duffy789 ,

You can use try <expresson> otherwise <expression> to parse the correct value in the needed format. For example

try Date.From([Date]) otherwise Date.From([Zone])

This will parse the date from your supposed to be date column otherwise will parse the date from Zone column. HEre's a sample M code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIy1zUw1zUyMDJUitWJVjKw1DWwAHGNQHJgISQVOkrGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Zone = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"Zone", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Date2", each try Date.From([Date]) otherwise Date.From([Zone]), type date),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each try Number.From([Date]) otherwise Number.From([Zone]), Int64.Type)
in
    #"Added Custom1"

danextian_0-1689080465177.png

 

 

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

3 REPLIES 3
Duffy789
New Member

@danextian 

 

Sorry I managed to do one but i have several other files to do, when I cut and paste the code to another table (which uses a different source file) it is refering to the data from the orginal table, it is like it is using that as the source, how do I change the source to read from the new table/ the other file?

 

I think the issue is the table in the query was created manually so that is always goign to return those dates, how do i change the source 

Thanks 

Duffy789
New Member

Thanks, little bit of fiddling etc but that has done it 

danextian
Super User
Super User

Hi @Duffy789 ,

You can use try <expresson> otherwise <expression> to parse the correct value in the needed format. For example

try Date.From([Date]) otherwise Date.From([Zone])

This will parse the date from your supposed to be date column otherwise will parse the date from Zone column. HEre's a sample M code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIy1zUw1zUyMDJUitWJVjKw1DWwAHGNQHJgISQVOkrGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Zone = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"Zone", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Date2", each try Date.From([Date]) otherwise Date.From([Zone]), type date),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each try Number.From([Date]) otherwise Number.From([Zone]), Int64.Type)
in
    #"Added Custom1"

danextian_0-1689080465177.png

 

 

 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.