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),"")))))))

---------------------------------------------------------------------------------------------------------------------------


Was I helpful? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. It will help other users to find it faster.

follow me on Twitter @zmansuri123,
connect with me on LinkedIn from Here

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.

---------------------------------------------------------------------------------------------------------------------------


Was I helpful? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. It will help other users to find it faster.

follow me on Twitter @zmansuri123,
connect with me on LinkedIn from Here

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
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

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