Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
How to swap some values between two columns in power query using either GUI elements or M code?
Solved! Go to Solution.
Hi @Aasozab, I recommend you to create new pair of columns with extracted values:
[Extracted Date]
if (try Date.From([Column1]) otherwise false) is date then [Column1] else [Column2]
[Extracted Text]
if [Column1] = [Extracted Date] then [Column2] else [Column1]
Table.ReplaceValue(
your_table,
each [DOJ],
each [Designation],
(v, o, n) => if Value.Is(n, Text.Type) then v else if Value.Is(v, Text.Type) then n else o,
{"DOJ", "Designation"}
)
Hi, I dind´t provide the code with sample data, but you can create it either in power query vie Enger Data button or in excel and then import to power query.
The purpose was to show sou the way how to achieve expected result. You can use codes above by adding them separately as custom column. Just replace [Column1] with [DOJ] and [Column2] with [Designation]. Don't forget to set column name for first code: "Extracted Date".
Thank you for your reply. Would you plz tell me how can i download sample data you provided in the solution?
Hi @Aasozab, I recommend you to create new pair of columns with extracted values:
[Extracted Date]
if (try Date.From([Column1]) otherwise false) is date then [Column1] else [Column2]
[Extracted Text]
if [Column1] = [Extracted Date] then [Column2] else [Column1]
Hi @dufoq3 . I got these errors when followed your steps:
Please tell me:
1. whether or not I followed your steps correctly?
2. Why getting this error?
TIA
I have done so.
Check thse steps and plz tell where I have made a mistake. and why i am getting error in last step and plz also tell what would be next steps?
1
2
3
4
5
6
yes it works now. Thank you so much. I was confused by Note at bottom i.e. Note: Check this link to learn how to use my query. and was following these steps:
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.