cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tif
Helper II
Helper II

Nested IF returning Expression is Invalid from multiple choice Forms

Good afternoon, my apologies for what is likely to be a newbie question (yes, we all learn somewhere, and I'm hoping to learn from here!).  I have created a Forms questionnaire in which one of the questions requires the answer to be a single selection from 4 choices.  The point I am now stuck at involves nested IF for the 4 choices, and each choice returns a 3-digit code to the specified Excel column.  As an example:  if("apple", "5AA", if("banana", "5BB", if("carrot", "5CC", if("date", "5DD", "0"))))

 

Thank you for any and all guidance!

Tif

1 ACCEPTED SOLUTION

Accepted Solutions

@Tif 

 

Initialize a variable to store the value.

 

Use the Switch action to make it work as below:

On: Place the value you want to check

 

In the cases, please type following:

Case1: 

   condition :  Kent School District Diploma 

   set variable: 5KD

 

Repeat the same for other cases.

 

Then, In the Add rows to table action, store the variable value.

 

Regards

Krishna Rachakonda

If my reply helped you solving the issue, please mark the reply as Accepted Solution.

 

 

View solution in original post

17 REPLIES 17
rsaikrishna
Dual Super User
Dual Super User

@Tif 

 

Its the problem with double quote. Use single quote. 

 

Your expressions should be like this with single quote:

if('apple''5AA', if('banana''5BB', if('carrot''5CC', if('date''5DD''0'))))
 
Please give a try and let me know if you have any questions.
 
Regards
Krishna Rachakonda
If my reply helped you solving the issue, please mark the reply as Accepted Solution.

@rsaikrishna 

 

Thank you for your response.  I removed the double quotes and replaced them with single quotes.  I apologize, I neglected to note that there are multiple words in each identifier and I have the nesting as such:

 

if('apple_is_green''5AA', if('banana_is_yellow''5BB', if('carrot_is_orange''5CC', if('date_is_brown''5DD''0'))))

 

I ran a test with the above and here is the error message I have received: 

'The template language function 'if' expects its first parameter to be of type boolean. The provided value is of type 'String'.

 

Any and all suggestions are greatly appreciated!

 

Thank you!

Tif

@Tif 

 

I agree with the error message.

The template language function 'if' expects its first parameter to be of type boolean. The provided value is of type 'String'.

 

if('apple_is_green', '5AA', if('banana_is_yellow', '5BB', if('carrot_is_orange', '5CC', if('date_is_brown', '5DD', '0'))))

The above expression should have conditions after If statement.

 

For example:

if(FruitColor = 'apple_is_green', '5AA', if(FruitColor = 'banana_is_yellow', '5BB', if(FruitColor = 'carrot_is_orange', '5CC', if(FruitColor = 'date_is_brown', '5DD', '0'))))

 

In the place of FruitColor, you can place the variable or field which contains the color name.

 

Please let me know if you have any questions.

 

Regards

Krishna Rachakonda

If my reply helped you solving the issue, please mark the reply as Accepted Solution.

 

@rsaikrishna Thank you, I appreciate the assistance, but your recommendation does not work.  I am receiving the error message that the expression is invalid.  

 

I am not quite sure I understand the meaning of "variable."  Is the "variable" the location the response is being obtained from, or the location of where the response will be transferred to?

 

Also, I have read that numerical signs such as the equal sign (=) cannot be used, and it is required to use equals().  If I place equals() in the location you listed above for =, it appears to be an invalid expression.

 

 

 

 

 

@Tif 

 

Can you share screen shot of your complete flow and point out the location where you are trying to use this expression?

 

Regards

Krishna Rachakonda

If my reply helped you solving the issue, please mark the reply as Accepted Solution.

 

InkedFlow pic1.jpgFlow pic2.jpg@rsaikrishna @  Thank you, again, for your help with this.  Here are screenshots of my flow.  The Expression I have backed out to the original as it would not save the last suggestion due to the error.  Here is the Expression as I have it now (and is not functional)

if('Kent_School_District_Diploma','5KD',if('Kent_School_District_Part_Teacher/Online_GED','5KG',if('Green_River_College_Diploma/Degree/Certificate','5GD',if('Green_River_College_GED_Class','5GG','0'))))

 

Thanks again!  I do appreciate your help very much!

 
 

@Tif 

 

What is this field 9.JPG before expression? 

 

Let me know the above field complete 9.JPG

 

You should be placing this within the If to check the value and assign appropriate value.

 

Regards

Krishna

The field is:  Please select your Program of Interest:

 

 

@Tif 

 

Can you select "Please select your Program of Interest:" from your flow and paste here?  It will show some additional stuff.

 

Regards

Krishna

 

 

Flow3.jpg

@rsaikrishna Thank you, again, for all of your help!  Here is the pic you requested. 

 

@Tif 

 

Remove the field and expression from List School Attended field.

 

Place the following expression.

 

if(body('Get_response_details')?['r1aa30719b26a40978cadce7844c42558']='Kent_School_District_Diploma','5KD',if(body('Get_response_details')?['r1aa30719b26a40978cadce7844c42558']='Kent_School_District_Part_Teacher/Online_GED','5KG',if(body('Get_response_details')?['r1aa30719b26a40978cadce7844c42558']='Green_River_College_Diploma/Degree/Certificate','5GD',if(body('Get_response_details')?['r1aa30719b26a40978cadce7844c42558']='Green_River_College_GED_Class','5GG','0'))))

 

Give a try and let me know.

 

Regards

Krishna Rachakonda

If my reply helped you solving the issue, please mark the reply as Accepted Solution.

@rsaikrishna Sorry to say it didn't work.  I did delete the previous Expression, inserted the Expression you had provided.  I received the same error message of Invalid Expression.  I then replaced = with equals(   and again, Invalid Expression error.  I'm not giving up just yet...I'm determined to make this work.  

@Tif 

 

I am very determined to make this work as well. Thank you for quick replies. I am not sure if the numbers in the field name is wrong.

 

Store the value in "Please select your Program of Interest:" in a variable. and let us use it in the expression. So that, we don't see very long field name in the expression.

 

Regards

Krishna Rachakonda 

v-bacao-msft
Community Support
Community Support

 

Hi @Tif ,

 

The configuration below Maybe is the method described by @rsaikrishna , please take a try.

Fill the answer in Compose so that we could fill the output of Compose in expression directly.

151.PNG

if(equals(outputs('Compose'),'apple'), '5AA', if(equals(outputs('Compose'),'banana'), '5BB', if(equals(outputs('Compose'),'carrot'), '5CC', if(equals(outputs('Compose'),'date'), '5DD', '0'))))

 

Best Regards,

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

@Tif 

 

Thank you for pointing @v-bacao-msft 

 

Use following expression directly:

if(equals(body('Get_response_details')?['r1aa30719b26a40978cadce7844c42558'],'Kent_School_District_Diploma'),'5KD',if(equals(body('Get_response_details')?['r1aa30719b26a40978cadce7844c42558'],'Kent_School_District_Part_Teacher/Online_GED'),'5KG',if(equals(body('Get_response_details')?['r1aa30719b26a40978cadce7844c42558'],'Green_River_College_Diploma/Degree/Certificate'),'5GD',if(equals(body('Get_response_details')?['r1aa30719b26a40978cadce7844c42558'],'Green_River_College_GED_Class'),'5GG','0'))))

 

OR

 

Please the field "Please select your Program of Interest:" in compose action and use following expression:

if(equals(outputs('Compose'),'Kent_School_District_Diploma'),'5KD',if(equals(outputs('Compose'),'Kent_School_District_Part_Teacher/Online_GED'),'5KG',if(equals(outputs('Compose'),'Green_River_College_Diploma/Degree/Certificate'),'5GD',if(equals(outputs('Compose'),'Green_River_College_GED_Class'),'5GG','0'))))

 

Regards

Krishna Rachakonda

If my reply helped you solving the issue, please mark the reply as Accepted Solution.

@Tif 

 

Initialize a variable to store the value.

 

Use the Switch action to make it work as below:

On: Place the value you want to check

 

In the cases, please type following:

Case1: 

   condition :  Kent School District Diploma 

   set variable: 5KD

 

Repeat the same for other cases.

 

Then, In the Add rows to table action, store the variable value.

 

Regards

Krishna Rachakonda

If my reply helped you solving the issue, please mark the reply as Accepted Solution.

 

 

View solution in original post

@rsaikrishna Thank YOU!!!  It worked fantastically!!!  I cannot tell you how much I appreciate all of your time, assistance and patience!!!  

 

Thank you, again!!!

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (32,904)