cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
wshalex123
Helper IV
Helper IV

Map Array with Select() Action

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
 
 
 
2 ACCEPTED SOLUTIONS

Accepted Solutions
Chriddle
Super User
Super User

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.

View solution in original post

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"
  }
]

----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

View solution in original post

10 REPLIES 10
grantjenkins
Super User
Super User

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?

----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

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. 
Chriddle
Super User
Super User

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.

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"
  }
]

----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

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

wshalex123
Helper IV
Helper IV

Thank you both for the solutions! @Chriddle @grantjenkins 

wshalex123
Helper IV
Helper IV

@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? 

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


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

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.

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. 

Helpful resources

Announcements

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (4,727)