Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Unanswered

Advanced Array Comparision

(0) ShareShare
ReportReport
Posted on by 80
Hi good people,
 
From a Select action in Power Automate, I get a "Project Crew" array as an output. This array contains Resources. Every Resource has a LabotType and Units.
Here is an example of a Project Crew that has 3 Resources (but 4 units in total):
{
  "body": [
    {
      "laborType": "581dc2ac-427b-ef11-a671-6045bdd755fb",
      "units": 1
    },
    {
      "laborType": "ed0f66ec-4d3a-ef11-8409-000d3a580b08",
      "units": 2
    },
    {
      "laborType": "tt4d9dhh-499c-ef11-6400-858d3bdjf96d",
      "units": 1
    }
  ]
}
 
From another Select action I get an array of "Crew Templates". Each Crew Template has an ID and an array of Resources, where here as well - every Resource has a labor type and Units. In this object, these properties are named _dkt_labortype_value and dkt_units. 
Here is an example of an array of two Crew Templates, each has two Resources. 
{
    "body": [
        {
            "Crew Template ID": "12726c24-9b8d-ef11-ac21-6045bdd73f51",
            "Crew Template Resources": [
                {
                    "dkt_productiondefaultresourceid@odata.type": "#Guid",
                    "dkt_productiondefaultresourceid": "241176fd-8b90-ef11-ac21-6045bdd73f51",
                    "_dkt_labortype_value@OData.Community.Display.V1.FormattedValue": "Operator",
                    "_dkt_labortype_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "dkt_LaborType",
                    "_dkt_labortype_value@Microsoft.Dynamics.CRM.lookuplogicalname": "dkt_labortype",
                    "_dkt_labortype_value@odata.type": "#Guid",
                    "_dkt_labortype_value": "ed0f66ec-4d3a-ef11-8409-000d3a580b08",
                    "_dkt_productiondefault_value@OData.Community.Display.V1.FormattedValue": "1 Operator, 1 General Foreman",
                    "_dkt_productiondefault_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "dkt_ProductionDefault",
                    "_dkt_productiondefault_value@Microsoft.Dynamics.CRM.lookuplogicalname": "dkt_productiondefault",
                    "_dkt_productiondefault_value@odata.type": "#Guid",
                    "_dkt_productiondefault_value": "12726c24-9b8d-ef11-ac21-6045bdd73f51",
                    "dkt_units@OData.Community.Display.V1.FormattedValue": "1",
                    "dkt_units": 1,
                    "dkt_name": "PDR-1000"
                },
                {
                    "dkt_productiondefaultresourceid@odata.type": "#Guid",
                    "dkt_productiondefaultresourceid": "0cee8b43-8e90-ef11-ac21-6045bdd73f51",
                    "_dkt_labortype_value@OData.Community.Display.V1.FormattedValue": "General Foreman",
                    "_dkt_labortype_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "dkt_LaborType",
                    "_dkt_labortype_value@Microsoft.Dynamics.CRM.lookuplogicalname": "dkt_labortype",
                    "_dkt_labortype_value@odata.type": "#Guid",
                    "_dkt_labortype_value": "581dc2ac-427b-ef11-a671-6045bdd755fb",
                    "_dkt_productiondefault_value@OData.Community.Display.V1.FormattedValue": "1 Operator, 1 General Foreman",
                    "_dkt_productiondefault_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "dkt_ProductionDefault",
                    "_dkt_productiondefault_value@Microsoft.Dynamics.CRM.lookuplogicalname": "dkt_productiondefault",
                    "_dkt_productiondefault_value@odata.type": "#Guid",
                    "_dkt_productiondefault_value": "12726c24-9b8d-ef11-ac21-6045bdd73f51",
                    "dkt_units@OData.Community.Display.V1.FormattedValue": "1",
                    "dkt_units": 1,
                    "dkt_name": "PDR-1001"
                }
            ]
        },
        {
            "Crew Template ID": "ac6a9157-9f8d-ef11-ac21-6045bdd755fb",
            "Crew Template Resources": [
                {
                    "dkt_productiondefaultresourceid@odata.type": "#Guid",
                    "dkt_productiondefaultresourceid": "ea8abe39-9290-ef11-ac21-6045bdd73f51",
                    "_dkt_labortype_value@OData.Community.Display.V1.FormattedValue": "Operator",
                    "_dkt_labortype_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "dkt_LaborType",
                    "_dkt_labortype_value@Microsoft.Dynamics.CRM.lookuplogicalname": "dkt_labortype",
                    "_dkt_labortype_value@odata.type": "#Guid",
                    "_dkt_labortype_value": "ed0f66ec-4d3a-ef11-8409-000d3a580b08",
                    "_dkt_productiondefault_value@OData.Community.Display.V1.FormattedValue": "2 Operator, 1 General Foreman",
                    "_dkt_productiondefault_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "dkt_ProductionDefault",
                    "_dkt_productiondefault_value@Microsoft.Dynamics.CRM.lookuplogicalname": "dkt_productiondefault",
                    "_dkt_productiondefault_value@odata.type": "#Guid",
                    "_dkt_productiondefault_value": "ac6a9157-9f8d-ef11-ac21-6045bdd755fb",
                    "dkt_units@OData.Community.Display.V1.FormattedValue": "2",
                    "dkt_units": 2,
                    "dkt_name": "PDR-1002"
                },
                {
                    "dkt_productiondefaultresourceid@odata.type": "#Guid",
                    "dkt_productiondefaultresourceid": "dd4cb93f-9290-ef11-ac21-6045bdd73f51",
                    "_dkt_labortype_value@OData.Community.Display.V1.FormattedValue": "General Foreman",
                    "_dkt_labortype_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "dkt_LaborType",
                    "_dkt_labortype_value@Microsoft.Dynamics.CRM.lookuplogicalname": "dkt_labortype",
                    "_dkt_labortype_value@odata.type": "#Guid",
                    "_dkt_labortype_value": "581dc2ac-427b-ef11-a671-6045bdd755fb",
                    "_dkt_productiondefault_value@OData.Community.Display.V1.FormattedValue": "2 Operator, 1 General Foreman",
                    "_dkt_productiondefault_value@Microsoft.Dynamics.CRM.associatednavigationproperty": "dkt_ProductionDefault",
                    "_dkt_productiondefault_value@Microsoft.Dynamics.CRM.lookuplogicalname": "dkt_productiondefault",
                    "_dkt_productiondefault_value@odata.type": "#Guid",
                    "_dkt_productiondefault_value": "ac6a9157-9f8d-ef11-ac21-6045bdd755fb",
                    "dkt_units@OData.Community.Display.V1.FormattedValue": "1",
                    "dkt_units": 1,
                    "dkt_name": "PDR-1003"
                }
            ]
        }
    ]
}
 
My task:
I need to check which of the Crew Templates are included in the Project Crew.
Note, even if the Project Crew has other Resources on top of the Crew Template's Resources, this is still a match. As long as all Crew Template's Resources exist in the Project Crew (the order doesn't matter), with the same number of Units, then this is a match, and I want to return the associated Crew Template ID.
 
In the example above, the second Crew Template is my winner, because both its Resources (2 Units of Labor Type/_dkt_labortype_value = ed0f66ec-4d3a-ef11-8409-000d3a580b08, and 1 Units of Labor Type/_dkt_labortype_value = 581dc2ac-427b-ef11-a671-6045bdd755fb) exist in the Project Crew.
 
Challenges:
  • I'm trying to avoid Apply to each.
  • The arrays to compare are within another array. 
  • The properties are not named the same between both arrays. I couldn't solve that with Select because the arrays are inside another array.
If you can guide me how to solve it either with Select to choose just the data I want from the second array of arrays, or to use XML/XPATH to manipulate it... or any other efficient idea that will not involve apply to each it will be greatly appreciated.
Thanks,
Gil.
Categories:
  • shalem120kjh Profile Picture
    80 on at
    Advanced Array Comparision
    I have found the way to solve it with one apply to each, on the Crew Templates array (note: In my flow, Production Defaults = Crew Template).
    For every Crew Template, I shape all Resources to have the same shape as the Project Crew Resource. Then, I filter the Crew Template for Resources that are not included in the Project Crew. If the result is zero, that means that all Crew Template Resources are included in the Project Crew, therefore this is the Crew Template that I'm looking for. 
     
    I'm still looking for a more efficient way of doing this, that will not involve an Apply to each.
    Thanks,
    Gil.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 566 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 516 Super User 2025 Season 1

#3
stampcoin Profile Picture

stampcoin 492