Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
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
Solved! Go to Solution.
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"
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
Thanks, little bit of fiddling etc but that has done it
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"
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
85 | |
79 | |
54 | |
39 | |
35 |
User | Count |
---|---|
102 | |
80 | |
48 | |
48 | |
48 |