Data Mapper Patterns: Distinct Values
Published Aug 09 2023 06:52 AM 1,957 Views
Microsoft

In this post, we are going to discuss how we can retrieve distinct values from an array of records. We will be able to achieve this using the Distinct Values function.

 

Pre-requisites

To build this demo, we will need a sample file and schema. Within the SampleFiles.zip attachment in this post you will find a sample message and a schema that can be used for both the Source and Destination. Within this file, you will notice that we have two instances of the value 12. We would like have a distinct list of values and subsequently exclude one of these 12s.

 

 

{
   "Array":[
       {
            "value":12
       },
       {
            "value":12
       },
       {
            "value":11
       },
       {
            "value":9
       }
   ]
}

 

 

Building our Map

Within the SampleFiles.zip file we will discover a sample schema that we can use for both our source and destination schema. When we add our source and destination schemas we now need to configure our map. Expand your destination so that it looks like the following image and then add all your source elements.

 

KentWeareMSFT_1-1691452663002.png

 

The way our solution works is that you need to establish a loop that will transfer all the records from the source to the destination. 

KentWeareMSFT_3-1691453605433.png

 

If we test our map at this point, we will see all of our records come across. 

KentWeareMSFT_4-1691453727010.png

 

We now want to add our Distinct Values function but want to add it to our existing loop. The way to do this is by clicking on the sign on our loop like the following.

KentWeareMSFT_5-1691453850112.png

 

In the Functions panel, search for Distince Values and click on it.

KentWeareMSFT_0-1691536169251.png

 

Expand the Distinc Values function. you should see <ArrayItem> is already mapped to Collection. We now need to drag value to Collation.

KentWeareMSFT_1-1691536307310.png

 

Click Save

KentWeareMSFT_0-1691536443935.png

 

Click Generate so that the underlying XSLT file can be created which is used by the Test experience.

KentWeareMSFT_1-1691536692128.png

 

We can test our map using the sample file (SampleArrayMessage.json) found in the SampleFiles.zip

KentWeareMSFT_2-1691536870745.png

 

Our output should reflect the following. Notice, we only have one value of 12.

KentWeareMSFT_3-1691537449132.png

 

Video Content

If you would like to see this content in video format, please check out the following YouTube video.

 

Co-Authors
Version history
Last update:
‎Aug 09 2023 06:51 AM
Updated by: