Showing results for 
Search instead for 
Did you mean: 
Helper II
Helper II

Switch, but allows multiple correct answers

So, I have an inspection form in an app. For each inspection item where a deficiency is found, I want to add supplemental information to a report that I then email to the user.


I order to do this, I have two tables serving as the back-end data source for my app. I pull these tables into collections for use in the app. One table (Inspections) has one record per inspection and many fields (representing the inspection questions) with y/n values. Another table is the SupplementaryInfo where there is a record for each inspection question with best practices, citation info etc. 


I would like to use a Switch-like function to reference the SupplementaryInfo record for each inspection field containing a "no" value.


I need to reference records in one collection (SupplementaryInfo) based on field values in another collection (Inspections). So far I've tried this:

Filter(SupplementaryInfo, Switch( ThisItem.Q2 = "no", Q="2", ThisItem.Q3 = "no", Q="3", ThisItem.Q2 = "no" And ThisItem.Q3 = "no", Q= "2" Or Q="3"))


This code exists in a gallery displaying Inspections records, so ThisItem is referring to a single record in Inspections. Q# refers to a field in the Inspection collection (such as Inspection.Q2) and Q is a field in the SupplementaryInfo collection indicating what Inspection.field the record is referring to (the record where Q = 1 in SupplmentaryInfo has info related to field Inspections.Q1).


The above works, except for the case where Q2 and Q3 are both equal to "no". In this case, the Switch function sees that Q2 is "no" and stops and never gets to Q2 and Q3 = "no". I know that this case is trivial as I could put the Q2 and Q3 = "no" switch first, but my inspection form has many questions and the issue becomes exponentially more complicated with more fields to manage.


How can I choose multiple SupplementaryInfo records based on the values of the fields in my Inspection collection?

Community Support
Community Support

Hi @Jdscott,


Did you use this formula in the Items property of the gallery? If so, the items inside the gallery is from data source "SupplementaryInfo" not "Inspections". Because the you used the syntax FilterTableFormula1 [, Formula2, ... ] ) and the table is SupplementaryInfo. One Gallery can only recognize one data source. That is to say, if you want to filter Inspections by records in SupplementaryInfo, then you will have to put records of SupplementaryInfo in another control, and filter Inspections using that control, not using the table directly.


Also, the syntax of Switch function should be:

Switch( Formula, Match1, Result1 [, Match2, Result2, ... [, DefaultResult ] ] )

  • Formula - Required. Formula to evaluate for matches. This formula is evaluated only once.
  • Match(s) - Required. Values to compare with the result from Formula. If an exact match is found, the corresponding Result is returned.
  • Result(s) - Required. The corresponding value to return when an exact match is found.
  • DefaultResult - Optional. If an exact match isn't found, this value is returned. If you don't specify this argument, blank is returned.

That is to say, the formula should be something like:

Switch( ThisItem.Q2, "no", "Result")

I also cannot say that I have fully understand what you want to achieve, could you please give some data examples with these to tables and explain with the data?





Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks, Mona. My Switch function was incorrect! The test report generates with the correct data now. I've attached an image of the test app I generated to play and solve this problem. 


html report image.jpg


The Items property of my gallery is "Inspections". Inside of the gallery I have an html text box with my report. The report has two tables in it. One is the inspection data selected by - ThisItem.InspectionNumber. The other is the supplementary info table which should show certain records based on the fields in ThisItem.Q1 and ThisItem.Q2. I hope this explanation helps.

The way the supplementary table is populated is by a switch function containing all possible combinations of answers for Q1 and Q2. PowerApps searches through the switch functions until the single match is found and displays the relevant records from the supplementary info table. This is fine in my test case where I have 2 questions with 2 possible answers (yes or no), but impossible with any realistic number of inspection questions. 10 yes or no questions would require me to add 2^10 possible combinations of answers in my switch function. Ha!


Here is the portion of the html code which creates the supplementary info table in my report. The first block of code creates tables headers (columns) and the second populates those columns with data from my collection. Note the line beginning with "Concat". This line filters records from SupplementaryInfo (Ss) by only displaying info related to questions answered "no". "ThisItem" refers to a single record in the Inspections collection, as that is the data source for the gallery in which the html text is embedded. So, when an inspection has "no" for an answer to Question 1 (Q1), supplementary info about Q1 is displayed and so on.

<p style='font-weight:bold'>Supplementary Info:</p>

<table style='width:100%'>
    <th style='width:5em'>Q</th>
    <th style='width:5em'>S1</th>
    <th style='width:5em'>S2</th>

Concat(Filter(Ss, Switch( ThisItem.Q1&" "&ThisItem.Q2, "no no", Q="1" Or Q="2", "no yes", Q="1", "yes no", Q="2")),
    <td style='text-align:center'>"&Q&"</td>
    <td style='text-align:center'>"&S1&"</td>
    <td style='text-align:center'>"&S2&"</td>

What I want is for a Switch-like function that evaluates all possible answers and selects all which are true, instead of only selecting one match. then I could simply write: 


Concat(Filter(Ss, Switch( ThisItem.Q1 = "no", Q="1", ThisItem.Q2 = "no", Q="2",  ... ThisItem.Qn = "no", Q = "n"))

Is there a function like that? Or a way to work around to get to a much simpler code than hard-coding every possible combination of answers into my report?


 Edited to add image

Helpful resources

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.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (3,123)