cancel
Showing results for
Search instead for
Did you mean:
Frequent Visitor

## Complex(ish) logic from forms

Hi all; this is a followup to a previous post Sum form entries for logic?

Essentially, we have a form with 10 multiple choice questions, where the possible answers are "yes," "no," and "unsure."

Question 1 is a branching question – an answer of “no” will skip the 9 multiple choice questions and go straight to a final “any other info” question for free text entry.

We'd like there to be three possible outcomes. Outcome 1 is the overriding one, i.e. if a response satisfies the criteria for multiple outcomes, then outcome 1 is applied.

Outcome 1) If the answers to 2 or more of questions 2-10 are yes, send email A.

Outcome 2) If the answers to 1 or more of questions 2-10 is unsure, send email B.

Outcome 3) any other combination, send email C.

We'd also like to record the responses to the form, and the outcome, in a spreadsheet hosted on our MS Teams.

I’m aware there are a few different issues in this query and would greatly appreciate any guidance you can give.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

@John88 there may well be more elegant ways to do this but here is my solution. The form just uses a Yes/No response, "Is Spain in the EU" is one of the questions, the rest follow the same format.

As I always do, I save the form response to a SharePoint list:

Next, add a parallel branch for each question. As there are 10 questions and it's very wide only 2 of the branches are shown. In each branch add 2 Compose controls and add an expression to each as follows:

1) if(equals(body('Create_item')?['Lithuania'],'Yes'),1,0) - this converts the Yes/No to 1 or 0;

2) int(outputs('Compose_Lithuania')) - this converts the output of the Compose above to an integer.

Below all of the parallel branches add another Compose to do the addition of all the integer Composes controls above. This will use the following syntax:

``````add(outputs('Portugal'),
add(outputs('Greece'),
add(outputs('Malta'),
add(outputs('Belgium'),
add(outputs('Sweden'),
add(outputs('Lithuania'),
add(outputs('Luxembourg'),
add(outputs('Estonia'),
add(outputs('Spain'),
outputs('Finland')
)))))))))``````

Next we add a condition to check if the addition totals 2 or more. If it does we send one type of email, if it doesn't we send another.

In my example, I answered Yes to 8 of the 10 questions. The Compose Addition gave the correct result and the correct email was sent:

Rob
Los Gallardos
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

3 REPLIES 3
Frequent Visitor

As an update to this, instead of starting a new thread, I have simplified the responses into Yes and No, where 2 or more "yes" = email A, and otherwise email B.

I am trying to do this by converting "Yes" into 1, and otherwise 0, so I can perform a simple condition at the end. However, the flow is returning a 0 for every question, regardless if the answer is yes or no. The logic I'm using is:

int(if(equals(body('Get_response_details')?['response1'],'Yes'),1,0))

I was hoping to re purpose @ScottShearer 's super helpful guidance for this, but It doesn't appear to have worked - I may be missing something very obvious!

Thanks, John

Thanks,

John

Super User

@John88 there may well be more elegant ways to do this but here is my solution. The form just uses a Yes/No response, "Is Spain in the EU" is one of the questions, the rest follow the same format.

As I always do, I save the form response to a SharePoint list:

Next, add a parallel branch for each question. As there are 10 questions and it's very wide only 2 of the branches are shown. In each branch add 2 Compose controls and add an expression to each as follows:

1) if(equals(body('Create_item')?['Lithuania'],'Yes'),1,0) - this converts the Yes/No to 1 or 0;

2) int(outputs('Compose_Lithuania')) - this converts the output of the Compose above to an integer.

Below all of the parallel branches add another Compose to do the addition of all the integer Composes controls above. This will use the following syntax:

``````add(outputs('Portugal'),
add(outputs('Greece'),
add(outputs('Malta'),
add(outputs('Belgium'),
add(outputs('Sweden'),
add(outputs('Lithuania'),
add(outputs('Luxembourg'),
add(outputs('Estonia'),
add(outputs('Spain'),
outputs('Finland')
)))))))))``````

Next we add a condition to check if the addition totals 2 or more. If it does we send one type of email, if it doesn't we send another.

In my example, I answered Yes to 8 of the 10 questions. The Compose Addition gave the correct result and the correct email was sent:

Rob
Los Gallardos
If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

Frequent Visitor

Thanks so much for this Rob - you've made my day!

## Helpful resources

Announcements

#### Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

#### Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,961)