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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.