cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lauren_
Advocate IV
Advocate IV

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
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.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,848)