How do you select only the first value of a field within the “Apply To Each” and append it to a string variable

Shepherd, Edward 0 Reputation points
2023-08-12T15:57:14.9533333+00:00

Hello.  I am trying to use the Power Automate functionality within Power BI and am struggling to figure out how to select only the first value of a field within the “Apply To Each”, and append it to a string variable and use this variable in query to filter results. Screen Shot 1

Screen Shot 2

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2023-08-12T16:02:30.93+00:00

    Hello, thank you for asking here:

    To select only the first value of a field within the “Apply To Each” in Power Automate and append it to a string variable and use this variable in query to filter results, you can use the Select action. The Select action is used to select a subset of properties from an object or an array of objects. You can use this action to select only the first item from an array.

    Here’s how you can do it:

    Add the Select action after the Apply to each action.

    In the From field, select the output of the Apply to each action.

    In the Map field, enter the following expression: first(body('Apply_to_each'))['FieldName']. Replace FieldName with the name of the field you want to select.

    In the Outputs field, enter the name of a variable that will store the selected value.

    You can then use this variable in your query to filter results.

    I hope this helps!


  2. Shepherd, Edward 0 Reputation points
    2023-08-13T01:45:37.6866667+00:00

    I did try to use the "Current Item" and got the following error message:

    Error message: Flow save failed with code 'InvalidTemplate' and message 'The template validation failed: 'The inputs of template action 'Select' at line '1 and column '4018' is invalid. Action 'Apply_to_each' must be a parent 'foreach' scope of action 'Select' to be referenced by 'repeatItems' or 'items' functions.'.'.

    I had the following expression in the Map field:

    first(body('Apply_to_each'))['Plan Sponsor Selected']
    
    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.