cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
martinav
Community Champion
Community Champion

Looking for expression to join arrays.

I thought I saw this before, but after an hour of looking, I cant find it.  Simply put.  I have two arrays, with a common DocumentID.  I just need to JOIN them goether ON DocumentID (using SQL lingo)

 

Array1:

 

 

[
  {
    "DocumentID": 1265,
    "PartNumber": "510009",
    "Rev": "1",
    "Description": "KBOV HANDLE BRACKET ASSEMBLY"
  },
  {
    "DocumentID": 2338,
    "PartNumber": "KBV8-N-FW",
    "Rev": "0",
    "Description": "KBV8-N-FW GENERAL ARRANGEMENT & BOM"
  },
  {
    "DocumentID": 5522,
    "PartNumber": "213155",
    "Rev": "0",
    "Description": ".125 X .50 DOWEL PIN CS"
  }
 
]

 

 

 

Array2:

 

 

[
  {
    "DocumentID": 1265,
    "Comment": "."
  },
  {
    "DocumentID": 2338,
    "Comment": "Exploded view still WIP."
  },
  {
    "DocumentID": 5522,
    "Comment": "."
  }

]

 

 

 

This is what I want:

 

 

 

[
  {
    "DocumentID": 1265,
    "PartNumber": "510009",
    "Rev": "1",
    "Description": "KBOV HANDLE BRACKET ASSEMBLY",
    "Comment": "."
  },
  {
    "DocumentID": 2338,
    "PartNumber": "KBV8-N-FW",
    "Rev": "0",
    "Description": "KBV8-N-FW GENERAL ARRANGEMENT & BOM",
    "Comment": "Exploded view still WIP."
  },
  {
    "DocumentID": 5522,
    "PartNumber": "213155",
    "Rev": "0",
    "Description": ".125 X .50 DOWEL PIN CS",
    "Comment": "."
  }
 
]

 

 

 

I'm sure there is a simple expression for this.

1 ACCEPTED SOLUTION

Accepted Solutions
DeepakS
Most Valuable Professional
Most Valuable Professional

Hi @martinav 

 

I am not sure if you have already solved your issue but i find this interesting and thought of  spending some time on it. i finally able to make it work (dont think its a best solution and i may need to work on improving it) but its working.

i uploaded working flow at github: 

https://github.com/DeepakS22/DPowerAutomate/blob/master/MergeJSON_20200327174700.zip

 

Have a look and let me know if that helps.

 

Regards,

 

 

View solution in original post

15 REPLIES 15
PowerBack19
Impactful Individual
Impactful Individual

@martinav - Have you tried using the "Append to an Array variable"? Here is a video that covers this: https://www.youtube.com/watch?v=VAfwiN-vARQ

@PowerBack19 ,

 

Append adds records.  It does not add items, or "columns" depending on data source.  If you see my data examples, its merging or joining records keyed on DocumentID.  Again, terms depending on the system you are familiar with, SP, SQL, etc.

I could get there if there is a way to use an expression to get the current item() from these two select functions.  I could combine together.  Of course none of the attempts to write the expression work.

 

image.png

 

Results:

 

image.png

Ive wasted an entire day on this.  This is one of those times I loathe this system.  This is so forking simple.  Has to be a way to do it.

Cant go back to the filter array either.  This is absurd.

 

image.png

@martinav 

WDL limitations are usually frustrating.

I have managed to join elements from two different arrays (lets call them 'myInput1Array' and 'myInput2Array') when both elements shared a common property value, but it is very time consuming both on the design and on the performance.

 

So, you need to initialize a third array variable, let's call it 'myOutputArray', leave it empty for the moment.

Now, you use an Apply to each and assign as its input 'myInput1Array'

Inside the Apply to Each, you add a Filter Array and assign as its input 'myInput2Array', try to match common property value from current Apply to each iteration. Now you make sure a single match, if so, Append to array variable, name 'myOutputArray', value:

setProperty(setProperty(setProperty(json('{}'),'Property1FromArray1Name','Value'),'CommoProperty','Value'),Property1FromArray2Name','Value')

So, property values from myInput1Array are obtained from 

items('Apply_to_each')

And, property values from myInput2Array are obtained from

first(body('Filter_array'))

As I mentioned, very inneficient but saved my day

Hope this helps

Did I make your day? If so, mark my response as 'Solution' !!!

También escribo sobre Power Automate en este Blog y en Twitter

@efialttes ,

 

You have NO idea how much I appreciate the help of others here.  I am working through this solution.  I think of myself as pretty savvy with this type of thing, but I will tell you.  The absolute convolution of how many things work in this system is very troubling.  I am completely dumbfounded on how people come up with solutions like this.  Even with the answer right in front of me, and using the SAME names, etc, it is still very difficult to get everything right to make it work.  I'm still working on it, and will report back when its working.  I need to implement this solution to several flows.

 

Its funny, because to do the exact same thing in powerapps is also a trick. I can get my head around it better, but it took a while to figure out the ForAll() statement.  What is sooo simple in SQL (JOIN statement).  I still have to study what I did on other apps in order to use it again, but I have a solution on that side of the power platform.  I do find it interesting that these tools are designed as "code free", but when it comes down too it, you have to know more different types of code in order to get things to work the way you want.  If you are super simple, you can get out of it, but if you do anything of real depth, then you have to figure out MANY different languages.  ODATA, JSON, and Expressions (flow) just to name a couple.  Doing the same type of thing in PowerApps compared to Flow is an entirely different animal and requires very different knowledge.

 

Sorry, I'm whining a bit.  I'll report on progress.

Hi!

I understand your concerns: PowerApps with its own language, Power Automate too, ODATA... sometimes is a bit frustrating... The dream of zero code is still a dream, even thought Microsoft is putting lots of efforts to help us

Hope your story will have a happy ending... please let us know your progress on your challenge

Thanx!

 

Did I make your day? If so, mark my response as 'Solution' !!!

También escribo sobre Power Automate en este Blog y en Twitter

DeepakS
Most Valuable Professional
Most Valuable Professional

Hi @martinav 

 

I am not sure if you have already solved your issue but i find this interesting and thought of  spending some time on it. i finally able to make it work (dont think its a best solution and i may need to work on improving it) but its working.

i uploaded working flow at github: 

https://github.com/DeepakS22/DPowerAutomate/blob/master/MergeJSON_20200327174700.zip

 

Have a look and let me know if that helps.

 

Regards,

 

 

martinav
Community Champion
Community Champion

@DeepakS ,

 

Oh, I most certainly have not resolved my issue.  I thought it would be easy to just make a SQL View, because it is a simplified form of a view I already have.  However, that also is failing, and I have beat on it for several hours.  Side-by side comparison with an existing, and its been expressly perfect, but does not work.  I'm about to bail on this.

 

However, I was surprised by your post.  Of course, I'm confronted once again with an unknown, and unintuitive task... which is how the hello do you import a flow from what you have given.  Especially since I had no idea that you could even export them.  

 

I will try it if this task is not a multi-hour challenge.

 

Any direction on where to go to do this?

 

Thank you.

DeepakS
Most Valuable Professional
Most Valuable Professional

Hi @martinav 

 

Yes you can export/import. to import my flow just download it as it is and import here is an screen:

Import.png

 

martinav
Community Champion
Community Champion

@DeepakS ,

 

Interesting.  I have never seen that...

 

Trying it...

 

 

martinav
Community Champion
Community Champion

@DeepakS ,

 

Huh, well, lookie there.  That works.  I was dancing around this for hours.  Looks like you saved me a few more.

 

Nice job!

martinav
Community Champion
Community Champion

@DeepakS ,

 

A little update.  I added an additional source to merge.  Thus, I'm merging three arrays together.  Its as "simple" (after getting all of the syntax, language and usage correct) as adding another nested loop.  The disadvantage to this is it took over 2 minutes to run this part of the flow with 6 items in the items being acted upon.  Its only a once a day notification, so PA isnt waiting on it.  But, it is something to keep in mind.  Even two loops deep with 6 items tool over a minute to execute.  This will never be a large number.  I doubt it ever gets over 10 items, but that is something to consider with this method.  Of course, I'm not sure there is another method out there.  This is by far the simplest I saw.  Props to @DeepakS  for this!

 

image.png

DeepakS
Most Valuable Professional
Most Valuable Professional

Hi @martinav 

 

Yes , even i am not fully like my approach but as of now cant think of any other method, as we are merging two multi filed JSON :(. i can tell its complex in C# too ;).

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

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 (5,866)