How to swap the elements of an array

Priya Jha 896 Reputation points
2023-02-23T12:46:06.6666667+00:00

HI,

Is there any way to swap the elements of an array 

input = [1,2,3,4,5,6] 

swap 2nd index and 3rd index values 

Output= [1,2,4,3,5,6]

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,373 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,623 questions
{count} votes

2 answers

Sort by: Most helpful
  1. KranthiPakala-MSFT 46,642 Reputation points Microsoft Employee Moderator
    2023-02-24T23:33:32.71+00:00

    Hi @Priya Jha ,

    Thanks for using Microsoft Q&A forum and posting your query.

    You can use mapping data flow expression builder to achieve your requirement. You can utilize combination of mapIndex function and map function as below:

    
    mapIndex([1,2,3,4,5,6], iif(#index == 3, map([1,2,3,4,5,6], #item)[4], iif(#index == 4, map([1,2,3,4,5,6], #item)[3], #item)))
    

    User's image

    User's image

    Hope this helps.


    Please don’t forget to Accept Answer and Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

  2. Nandan Hegde 36,146 Reputation points MVP Volunteer Moderator
    2023-02-25T12:50:27.88+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.