cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lauren_
Helper V
Helper V

Label, multiple if statement for text

Hey guys, I'm having real problems with understanding if/switch/multiple if statements 😂

 

I'm trying to set up a label text so that depending on whether certain quoted words are in a field, it shows the relevant text. My If statement below has been taken but only shows the first one.

 

If("Analytical Chemistry" in Gallery2.Selected.LabsChosen,"Analytical Chemistry: "&Char(10)&Gallery2.Selected.'Ana-Fulfilment'&Char(10)&Char(10),
("Biochemistry" in Gallery2.Selected.LabsChosen),"Biochemistry: "&Char(10)&Gallery2.Selected.'Biochem-Fulfilment'&Char(10)&Char(10),
("Cell Biology" in Gallery2.Selected.LabsChosen),"Cell Biology: "&Char(10)&Gallery2.Selected.'CB-Fulfilment'&Char(10)&Char(10),
("Microbiology" in Gallery2.Selected.LabsChosen),"Microbiology: "&Char(10)&Gallery2.Selected.'Microb-Fulfilment'&Char(10)&Char(10),
("Molecular Biology" in Gallery2.Selected.LabsChosen),"Molecular Biology: "&Char(10)&Gallery2.Selected.'Molecb-Fulfilment'&Char(10)&Char(10),
("Preparative Chemistry" in Gallery2.Selected.LabsChosen),"Preparative Chemistry: "&Char(10)&Gallery2.Selected.'PrepChem-Fulfilment',
IsBlank(Gallery2.Selected.LabsChosen),"")

12 REPLIES 12
zmansuri
Super User
Super User

If("Analytical Chemistry" in Gallery2.Selected.LabsChosen,"Analytical Chemistry: "&Char(10)&Gallery2.Selected.'Ana-Fulfilment'&Char(10)&Char(10),
If("Biochemistry" in Gallery2.Selected.LabsChosen,"Biochemistry: "&Char(10)&Gallery2.Selected.'Biochem-Fulfilment'&Char(10)&Char(10),
If("Cell Biology" in Gallery2.Selected.LabsChosen,"Cell Biology: "&Char(10)&Gallery2.Selected.'CB-Fulfilment'&Char(10)&Char(10),
If("Microbiology" in Gallery2.Selected.LabsChosen,"Microbiology: "&Char(10)&Gallery2.Selected.'Microb-Fulfilment'&Char(10)&Char(10),
If("Molecular Biology" in Gallery2.Selected.LabsChosen,"Molecular Biology: "&Char(10)&Gallery2.Selected.'Molecb-Fulfilment'&Char(10)&Char(10),
If("Preparative Chemistry" in Gallery2.Selected.LabsChosen,"Preparative Chemistry: "&Char(10)&Gallery2.Selected.'PrepChem-Fulfilment',
If(IsBlank(Gallery2.Selected.LabsChosen),"")))))))

Hey Zmansuri, it takes that thank you but again only shows the first one 🤔 If two or more of those statements re in the field, I want it to show all of the relevant information, e.g. if Analytical Chemistry & Microbiology are in the field, show their true statement. Does that make sense? Is that possible?

it makes perfect sense. But, for some reason i can't seem to think of a way to do that. Straight forward approach would be to write all 36 combinations. But i am sure there must be good way to do it. 

@WarrenBelz  and @RandyHayes are good at this sort of things. Maybe they can help you.

Oh no this is what I was thinking, sadly it'd be more than 36 combinations as the user can select one to all six in any combination 😂😂😬

WarrenBelz
Super User
Super User

Hi @Lauren_ ,

If you want to display all the selected items, try this

With(
   {
      wChosen:Gallery2.Selected,
      wItems:Gallery2.SelectedItems,
      wBreak:Char(10) & Char(10)
   },
   If(
      "Analytical Chemistry" in wItems,
      "Analytical Chemistry" & wChosen.'Ana-Fulfilment' & wBreak
   ) &&
   If(
      "Biochemistry" in wItems,
      "Biochemistry" & wChosen.'Biochem-Fulfilment' & wBreak
   ) &&
   If(
      "Cell Biology" in wItems,
      "Cell Biology" & wChosen.'CB-Fulfilment' & wBreak
   ) &&
   If(
      "Microbiology" in wItems,
      "Microbiology" & wChosen.'Microb-Fulfilment' & wBreak
   ) &&
   If(
      "Molecular Biology" in wItems,
      "Molecular Biology" & wChosen.LabsChosen & wBreak
   ) &&
   If(
      "Preparative Chemistry" in wItems,
      "Preparative Chemistry" & wChosen.PrepChem-Fulfilment & wBreak
   ) 
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi Warren!

Thanks for replying, it's given me an error message, "cannot use record values in this context". 

 

Lauren__0-1631790222169.png

 

@Lauren_ ,

Problem with free-typing - I have had another go with corrected post. Note what you are trying to do is not straight-forward and I am not entirely confident this will work (I have a plan B if not)

Hey Warren, it was a good effort for free typing, much better than what I could do!! 

 

Sadly it's still kicking off over witems with the same error message. Could we try plan B?

@Lauren_ ,

wItems should not contain an error - it is simply referencing the combo SelectedItems. I was more concerned with wChosen. Note the With() statement is only to avoid repetitive typing. The problem with the reference to the other fields is that you have chosen more than one item, meaning the reference is not valid - so

With(
   {
      wItems:Gallery2.SelectedItems,
      wBreak:Char(10) & Char(10)
   },
   If(
      "Analytical Chemistry" in wItems,
      "Analytical Chemistry" &
      LookUp(
         YourListName,
         LabsChosen = "Analytical Chemistry"
      ).'Ana-Fulfilment' & wBreak
   ) &&
   If(
      "Biochemistry" in wItems,
      "Biochemistry" & 
      LookUp(
         YourListName,
         LabsChosen = "Biochemistry"
      ).'Biochem-Fulfilment' & wBreak
   ) &&
   If(
      "Cell Biology" in wItems,
      "Cell Biology" &
      LookUp(
         YourListName,
         LabsChosen = "Cell Biology"
      ).'CB-Fulfilment' & wBreak
   ) &&
   If(
      "Microbiology" in wItems,
      "Microbiology" & 
      LookUp(
         YourListName,
         LabsChosen = "Microbiology"
      ).'Microb-Fulfilment' & wBreak
   ) &&
   If(
      "Molecular Biology" in wItems,
      "Molecular Biology" & 
      LookUp(
         YourListName,
         LabsChosen = "Molecular Biology"
      ).'Molecb-Fulfilment' & wBreak
   ) &&
   If(
      "Preparative Chemistry" in wItems,
      LookUp(
         YourListName,
         LabsChosen = "Preparative Chemistry"
      ).PrepChem-Fulfilment & wBreak
   ) 
)

Please study this syntax before coming back - it is guidance based on the values you posted. If there is an issue with wItems, change it to Gallery2.SelectedItems.LabsChosen.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,392)