web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Map Array with Select(...
Power Automate
Unanswered

Map Array with Select() Action

(0) ShareShare
ReportReport
Posted on by 160

Hi all,

 

iam generating an Array, which is sent to PowerApps later, out of a Text File.

My Text file looks like this:

wshalex123_0-1698647632776.png

In an ApplyToAll loop iam removing all unrelevant lines/rows.
So the first output of the FilterArray Action looks like this: 

[
  "DXFSHEA3_1",
  "2157",
  "496.33",
  "0",
  "OFF",
  "1088.5",
  "258.165",
  "0",
  "10",
  "10",
  "0"
]
 
Now i want to sum all filtered rows into a variable, map them and send it back to PowerApps. This is where i don't now how to continue and nearly all tutorials on the web aren't working. I daresay that the input data is a mess yeah. 
 
This is my solution for now, but i know it's wrong and you can see it in the Select (Here: "Auswählen") Action:
wshalex123_1-1698648740255.png

 

Problem is iam getting mutiple results after the Select() Action, where only should be one!

 

[
  {
    "Artikel": "DXFSHEA3_1",
    "Länge": "2157",
    "Breite": "496.33",
    "X": "1088.5",
    "Y": "258.165"
  },
  {
    "Artikel": "DXFSHEA3_1",
    "Länge": "2157",
    "Breite": "496.33",
    "X": "1088.5",
    "Y": "258.165"
  },
 .... 
 
Thats probably because i should do the Select Action after the ApplyToAll? But if i do that, i got problems adding the output of filter array to the array variable...
 
Can anybody help me with a solution for this? 
 
Thanks in advance.
 
Cheers,
Alex
 
 
 
Categories:
I have the same question (0)
  • grantjenkins Profile Picture
    11,063 Moderator on at

    Just a few questions:

    1. Is your text file a tab delimited file?
    2. Is it possible to upload a copy of the file so we could work with it directly?
    3. What exactly are you trying to sum? Are you looking to add up all the lengths across all rows, all the angles across all the rows, etc.? Or is it grouped by Part Name - so sum of lengths across each of the Part Names?
  • wshalex123 Profile Picture
    160 on at

    Hi @grantjenkins,

     

    of course, i'll attach the file in this message. Open it with Notepad or edit.

    No it's delimited mit spaces. It's trash to work with, but i already made it work to remove all unrelevant rows and data. 

     

    Sum is the wrong word probably. All i want is the data of this file in an array format, to put it into a collection in PowerApps later on. The Lengths, Angles etc should not be summed. It should look something like this:

     

    {
            "Artikel": "DXFSHEA3_1",
            "Länge": "2157",
            "Breite": "496.33",
            "X": "1088.5",
            "Y": "258.165"
          },
          {
            "Artikel": "DXFSHEA3_1",
            "Länge": "2157",
            "Breite": "496.33",
            "X": "1088.5",
            "Y": "764.465"
          },
          {
            "Artikel": "DXFSHEA2_1",
            "Länge": "2057",
            "Breite": "437.67",
            "X": "1038.5,
            "Y": "1241.435"
          }

    ... and so on. So i can work with this data and process it. 
  • Verified answer
    Chriddle Profile Picture
    8,436 Super User 2025 Season 2 on at

    Chriddle_1-1698660124813.png

     

    Data

    Compose with the file content

     

    DataStringArray

    Compose that splits the lines and removes spaces

     

     

    split(
    	replace(
    		replace(
    			replace(
    				replace(
    					outputs('Data'),
    					' ',
    					' '
    				),
    				' ',
    				' '
    			),
    			' ',
    			' '
    		),
    		' ',
    		' '
    	),
    	decodeUriComponent('%0A')
    )

     

     

     

    DataStringArrayFilteredForEmpty

    Filter that removes empty lines

    From: @outputs('DataStringArray')

    Filter: @not(equals(item(), string(null)))

    This looks better 😉: @not(empty(item()))

     

    DataObjectArray

    Select that creates the objects

    From (Skip the headlines)

     

     

    skip(body('DataStringArrayFilteredForEmpty'), 5)

     

     

     article

     

     

    split(item(), ' ')[0]

     

     

    length

     

     

    split(item(), ' ')[1]

     

     

    width

     

     

    split(item(), ' ')[2]

     

     

     

    etc.

     

    NewData

    Compose that removes duplicates

     

     

    union(body('DataObjectArray'), json('[]'))

     

     

     

    Create HTML table

    Just to check the result

     

     

    sort(outputs('NewData'), 'article')

     

     

     

    The output:

    article length width x y
    DXFPAR0104_1 64.755 64.755 0 OFF
    DXFPAR0117_1 660 215 90 OFF
    DXFPAR0119_1 162 80 0 OFF
    DXFPAR0121_1 84.26 176.507 270 OFF
    DXFPART4_1 1200 650.002 270 OFF
    DXFPUNC0_1 293 162 180 OFF
    DXFPUNC5_1 670 257.07 0 OFF
    DXFSHEA2_1 2057 437.67 0 OFF
    DXFSHEA3_1 2157 496.33 0 OFF
    DXFSHEA4_1 636 281 90 OFF
    DXFSHEA7_1 100 50 90 OFF
    DXFSHEA7_1 100 50 0 OFF

     

    Note that there are two rows with article DXFSHEA7_1 because the y values are different.

    To get only one row per article you need to define which row to use and depending on this the object creation may be different.

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    Hopefully this is what you're after. I was trying to do it without using a loop, but no luck there.

     

    See full flow below. I'll go into each of the actions.

    grantjenkins_0-1698660353562.png

     

    Get file content using path retrieves the file.

    grantjenkins_1-1698660381170.png

     

    Compose converts the file content to text using the following expression.

    base64ToString(outputs('Get_file_content_using_path')?['body']?['$content'])

    grantjenkins_2-1698660432145.png

     

    Filter array Rows splits each row by carriage return and new line, then skips the first 5 rows (headers), and removes any empty rows (seems there are a few empty rows at the end of the file).

    //From
    skip(split(outputs('Compose'), decodeUriComponent('%0D%0A')), 5)
    
    //Condition
    item()

    grantjenkins_3-1698660571731.png

     

    Select uses the output from Filter array Rows and splits by space.

    //Map
    split(item(), ' ')

    grantjenkins_4-1698660636341.png

     

    Initialize variable creates a variable called data of type Array and sets it as an empty array.

    grantjenkins_5-1698660682091.png

     

    Apply to each uses the output from Select so it iterates over each of the rows of data.

    grantjenkins_6-1698660716855.png

     

    Filter array uses the Current item (current row we are iterating over) and removes any empty items.

    //Condition
    item()

    grantjenkins_7-1698660802257.png

     

    Append to array variable appends the fields for each item to the data variable.

    {
    "Artikel": @{body('Filter_array')?[0]},
    "Länge": @{body('Filter_array')?[1]},
    "Breite": @{body('Filter_array')?[2]},
    "X": @{body('Filter_array')?[5]},
    "Y": @{body('Filter_array')?[6]}
    }

    grantjenkins_8-1698661188868.png

     

    If we ran the flow now, the data array variable would contain an array of all the objects.

     

    After the Apply to each, I've added a Compose called Output that shows the value of our data array.

    grantjenkins_9-1698661272409.png

     

    A sample of the output is below (I've just shown the first 6 rows).

    grantjenkins_10-1698661312720.png

    [
     {
     "Artikel": "DXFSHEA3_1",
     "Länge": "2157",
     "Breite": "496.33",
     "X": "1088.5",
     "Y": "258.165"
     },
     {
     "Artikel": "DXFSHEA3_1",
     "Länge": "2157",
     "Breite": "496.33",
     "X": "1088.5",
     "Y": "764.465"
     },
     {
     "Artikel": "DXFSHEA2_1",
     "Länge": "2057",
     "Breite": "437.67",
     "X": "1038.5",
     "Y": "1241.435"
     },
     {
     "Artikel": "DXFPART4_1",
     "Länge": "1200",
     "Breite": "650.002",
     "X": "2502.001",
     "Y": "610"
     },
     {
     "Artikel": "DXFPUNC5_1",
     "Länge": "670",
     "Breite": "257.07",
     "X": "2412",
     "Y": "1348.535"
     },
     {
     "Artikel": "DXFSHEA4_1",
     "Länge": "636",
     "Breite": "281",
     "X": "2713.5",
     "Y": "605.7"
     }
    ]
  • Chriddle Profile Picture
    8,436 Super User 2025 Season 2 on at

    To avoid the loop, just remove the unnecessary spaces in advance.

  • wshalex123 Profile Picture
    160 on at

    Thank you both for the solutions! @Chriddle @grantjenkins 

  • wshalex123 Profile Picture
    160 on at

    @Chriddle i tried your solution but didn't get along with one error at the DataObjectArray (Select) Action.

     

    Inpu:

    [
      "DXFSHEA3_1 2157 496.33 0 OFF 1088.5 258.165 0 10 10 0 \r",
      "DXFSHEA3_1 2157 496.33 0 OFF 1088.5 764.465 0 10 516.3 0 \r",
      "DXFSHEA2_1 2057 437.67 0 OFF 1038.5 1241.435 0 10 1022.6 0 \r",
      "DXFPART4_1 1200 650.002 270 OFF 2502.001 610 270 2177 1210 0 \r",
      "DXFPUNC5_1 670 257.07 0 OFF 2412 1348.535 0 2077 1220 0 \r",
      "DXFSHEA4_1 636 281 90 OFF 2713.5 605.7 90 2854 287.7 0 \r",
      "DXFPAR0117_1 660 215 90 OFF 2878.5 1060.3 90 2986 730.3 0 \r",
      "DXFPUNC0_1 293 162 180 OFF 2803.5 196.4 180 2950 277.4 0 \r",
      "DXFPAR0121_1 84.26 176.507 270 OFF 2845.254 1377.33 270 2757 1419.46 0 \r",
      "DXFPAR0119_1 162 80 0 OFF 2666 973.7 0 2585 933.7 0 \r",
      "DXFPAR0119_1 162 80 0 OFF 2906 86.8 0 2825 46.8 0 \r",
      "DXFSHEA7_1 100 50 90 OFF 2102 1072.6 90 2127 1022.6 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2506 533 0 2456 508 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2506 675 0 2456 650 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2807 1245 0 2757 1220 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2807 1447.7 0 2757 1422.7 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2914 312.4 0 2864 287.4 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2914 372.4 0 2864 347.4 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2914 432.4 0 2864 407.4 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2914 492.4 0 2864 467.4 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2914 552.4 0 2864 527.4 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2914 612.4 0 2864 587.4 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2914 672.4 0 2864 647.4 0 \r",
      "DXFSHEA7_1 100 50 0 OFF 2917 1454.4 0 2867 1429.4 0 \r",
      "DXFSHEA7_1 100 50 90 OFF 2961 1056.3 90 2986 1006.3 0 \r",
      "DXFPAR0104_1 64.755 64.755 0 OFF 2109.378 1164.978 0 2077 1132.6 0 \r",
      "DXFPAR0104_1 64.755 64.755 0 OFF 2520.578 600.378 0 2488.2 568 0 \r",
      "DXFPAR0104_1 64.755 64.755 0 OFF 2527.378 382.478 0 2495 350.1 0 \r",
      "DXFPAR0104_1 64.755 64.755 0 OFF 2527.378 832.278 0 2495 799.9 0 \r",
      "DXFPAR0104_1 64.755 64.755 0 OFF 2608.378 244.178 0 2576 211.8 0 \r",
      "DXFPAR0104_1 64.755 64.755 0 OFF 2728.378 1040.378 0 2696 1008 0 \r",
      "\r",
      "\r"
    ]

    Error:
    The execution of template action 'DataObjectArray' failed: The evaluation of 'query' action 'where' expression '{
    "Artikel": "@split(item(), ' ')[0]",
    "Länge": "@split(item(), ' ')[1]",
    "Breite": "@split(item(), ' ')[2]",
    "Angle": "@split(item(), ' ')[3]",
    "X": "@split(item(), ' ')[5]",
    "Y": "@split(item(), ' ')[6]"
    }' failed: 'The template language expression 'split(item(), ' ')[1]' cannot be evaluated because array index '1' is outside bounds (0, 0) of array. Please see https://aka.ms/logicexpressions for usage details.'.

    I think It's because the last two "\r" you got this error too? You know how i also can skip the last two rows? 

  • grantjenkins Profile Picture
    11,063 Moderator on at

    Here's another more streamlined solution based on @Chriddle using replace to remove the spaces.

     

    grantjenkins_0-1698675103197.png

     

    Get file content using path is the same as before.

    grantjenkins_1-1698675130008.png

     

    Filter array uses the following expression.

    //From
    skip(
     split(
     replace(
     replace(
     replace(
     replace(
     base64ToString(outputs('Get_file_content_using_path')?['body']?['$content']),
     ' ',
     ' '
     ),
     ' ',
     ' '
     ),
     ' ',
     ' '
     ),
     ' ',
     ' '
     ), 
     decodeUriComponent('%0D%0A')
     ),
     5
    )
    
    //Condition
    item()

    grantjenkins_2-1698675273854.png

     

    Select uses the output from Filter array and the following mappings.

    //Artikel
    split(item(), ' ')[0]
    
    //Länge
    split(item(), ' ')[1]
    
    //Breite
    split(item(), ' ')[2]
    
    //X
    split(item(), ' ')[5]
    
    //Y
    split(item(), ' ')[6]

    grantjenkins_3-1698675371253.png

  • Chriddle Profile Picture
    8,436 Super User 2025 Season 2 on at

    This is handled by the Filter (DataStringArrayFilteredForEmpty) in my flow.

    In DataStringArray replace decodeUriComponent('%0A') with decodeUriComponent('%0D%0A')

     

    Which one you need to use depends on whether your text file uses Unix-style or Windows-style line breaks.

  • guventum Profile Picture
    3 on at

    How do you handle null values in the select when you manually put a item number in here? 

    for example when item()[0] (Artikel)  is null it will then point the [0] to item Länge etc. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard