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 Apps / Looking for the correc...
Power Apps
Answered

Looking for the correct way to deal with arrays and concat

(0) ShareShare
ReportReport
Posted on by 487

I generate a string out of elements in a gallery, each element may or may not be blank and may or maynot differ from two versions based on input from a form.
The current and obviously not best way to deal with this is: 

Left(
 Trim(
 Concat(
 [
 Text(
 If(
 IsBlank(ThisItem.Patch.INST_NO),
 ThisItem.Original.INST_NO,
 ThisItem.Patch.INST_NO
 )
 ),
 Text(
 If(
 IsBlank(ThisItem.Patch.NOM_DIAM),
 ThisItem.Original.NOM_DIAM,
 ThisItem.Patch.NOM_DIAM
 )
 ),
 Text(
 If(
 IsBlank(ThisItem.Patch.TAG),
 ThisItem.Original.TAG,
 ThisItem.Patch.TAG
 )
 ),
 Text(
 If(
 IsBlank(ThisItem.Patch.PIPING_CLASS),
 ThisItem.Original.PIPING_CLASS,
 ThisItem.Patch.PIPING_CLASS
 )
 ),
 Text(
 If(
 IsBlank(ThisItem.Patch.INSULATION_CLASS),
 ThisItem.Original.INSULATION_CLASS,
 ThisItem.Patch.INSULATION_CLASS
 )
 )
 ],
 If(
 IsBlank(Value),
 "",
 Value & "-"
 )
 )
 ),
 Len(
 Trim(
 Concat(
 [
 Text(
 If(
 IsBlank(ThisItem.Patch.INST_NO),
 ThisItem.Original.INST_NO,
 ThisItem.Patch.INST_NO
 )
 ),
 Text(
 If(
 IsBlank(ThisItem.Patch.NOM_DIAM),
 ThisItem.Original.NOM_DIAM,
 ThisItem.Patch.NOM_DIAM
 )
 ),
 Text(
 If(
 IsBlank(ThisItem.Patch.TAG),
 ThisItem.Original.TAG,
 ThisItem.Patch.TAG
 )
 ),
 Text(
 If(
 IsBlank(ThisItem.Patch.PIPING_CLASS),
 ThisItem.Original.PIPING_CLASS,
 ThisItem.Patch.PIPING_CLASS
 )
 ),
 Text(
 If(
 IsBlank(ThisItem.Patch.INSULATION_CLASS),
 ThisItem.Original.INSULATION_CLASS,
 ThisItem.Patch.INSULATION_CLASS
 )
 )
 ],
 If(
 IsBlank(Value),
 "",
 Value & "-"
 )
 )
 )
 ) - 1
)

This is such a mess, there must be a better way to deal with it. I have some experience with imperative languages, but I'm struggelig to keep the code "DRY" because I really have a hard time to wrap my head around certain declarative concepts. Whenever I create tiny ripples of complexity, they become tidalwaves further down the line causing the simplest functions hard to use; like in this case where i just want to join all elements with a "-" between each element.

Suggestions would be greatly appreciated! 🙂 

 

Categories:
I have the same question (0)
  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @hjaf 

    Although there are times when formulas can get a bit lengthy and challenging to deal with, there are still times when you have a complex scenario to deal with.  So, in those cases, the goal is to keep it simple and non-repetative.  Use other controls to help make it happen.

    So, in your example, you are repeating the logic of your Concat in order to just get the length of the result so you can trim the last "-" off of it.  This makes a formula lengthy and causes confusion if you have to change any aspect of the "core" formula (as it needs to be repeated in the second half).  So rather than to repeat the formulas, there is a quick way to deal with that...a second control (there are other ways, but this is simple and easy).  

    The other consideration is to take advantage of other "less known" functions like Coalesce to make your formula a little more manageable. 

     

    So, here's an example (based on the logic of your current formula) - create a Label Control (let's call it lblMyValue) and set the Text property to this:

     

    Trim(
    Concat( [ Text(Coalesce(ThisItem.Patch.INST_NO, ThisItem.Original.INST_NO)), Text(Coalesce(ThisItem.Patch.NOM_DIAM, ThisItem.Original.NOM_DIAM)), Text(Coalesce(ThisItem.Patch.TAG, ThisItem.Original.TAG)), Text(Coalesce(ThisItem.Patch.PIPING_CLASS, ThisItem.Original.PIPING_CLASS)), Text(Coalesce(ThisItem.Patch.INSULATION_CLASS, ThisItem.Original.INSULATION_CLASS)) ], If( IsBlank(Value), "", Value & "-" ) )
    )

     THEN, have an additional label (or simply consume the value of the above label) going forward.  Something like this in the Text property of the other label - 

     

     

    Left(lblMyValue.Text, Len(lblMyValue.Text) -1)

    You can set the vivible property to false on those labels if you don't want them to appear on the screen.

     

     

    Going beyond that...I personally like to put any formula that has any "teeth" to it (i.e. something that is important to the App that could change in the future) into a seperate screen or into a Component.  This way you only have ONE place to change a formula if needed. And, you also then have a place where you can always find your "teeth" formulas quickly.

     

    I hope this is helpful for you.

  • hjaf Profile Picture
    487 on at

    Thanks a lot for the informative reply,
    I will look more into using coalesce()!

     

    Using certain components or screens to organize those formulas is a good idea, thanks for the tip 🙂

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard