cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Cannot find mistake in expression

Hi,

 

I have a long (for me at least) expression which fails because it has 4 parameters instead of 3. Any help?

 

if(and(startswith(triggerBody()?['Apple'],'3'),triggerBody()?['Test']?['value'],true),'Monkey',if(and(startswith(triggerBody()?['Apple'],'4'),triggerBody()?['Test']?['value'],true),'Monkey'),
if(and(startswith(triggerBody()?['Apple'],'6'),triggerBody()?['Banana_x003f_']?['value'],true),'Monkey',if(and(startswith(triggerBody()?['Apple'],'6'),triggerBody()?['Test']?['value'],true),'Monkey'),
if(and(startswith(triggerBody()?['Apple'],'6'),triggerBody()?['Kiwi']?['value'],true),'Monkey'),if(startswith(triggerBody()?['Apple'],'7'),'Monkey'),''))

 

SQL language is so much easier in cases like this :(.

 

I want it like this:

If Apple starts with 3 and test=True then Monkey else

if Apple starts with 4 and test=true then Monkey else 

if apple starts with 6 and banana=true then Monkey else

if apple starts with 6 and test=true then Monkey else

if apple starts with 6 and kiwi=true then Monkey else

if apple starts with 7 then Monkey else null

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

 

and() works like an and gate for Boolean values. you need to supply Boolean type arguments. If they all equate to true, the and() expression will also return true. E.g.: and(true, true) would resolve to true.

 

If you want to are comparing several values to others, you do it like this:

 

E.g.: 

and(equals(a, 5), startswith(b,'a'))

 When a = 5 and b starts with 'a', both expressions are true and the and() expression will be true also.

 

Importantly, in PowerAutomate, the and() expression can only take two arguements. You cannot pass 3. 

 

For you, the code should like this:

 

if(and(startswith(triggerBody()?['Apple'],'3'), equals(triggerBody()?['Test']?['value'], true)),
    'Monkey',
    if(and(startswith(triggerBody()?['Apple'],'4'), equals(triggerBody()?['Test']?['value'],true)),
        'Monkey',
        if(and(startswith(triggerBody()?['Apple'],'6'), equals(triggerBody()?['Banana_x003f_']?['value'],true)),
            'Monkey',
            if(and(startswith(triggerBody()?['Apple'],'6'), equals(triggerBody()?['Test']?['value'],true)),
                'Monkey',
                if(and(startswith(triggerBody()?['Apple'],'6'), equals(triggerBody()?['Kiwi']?['value'],true)),
                    'Monkey',
                    if(startswith(triggerBody()?['Apple'],'7'),
                        'Monkey',
                        ''
                    )
                )
            )
        )
    )
)

 

 

View solution in original post

5 REPLIES 5
Kikoger
Resolver I
Resolver I

Hi,

 

If you want to test for a=b, then you need the equals function. Example:

 

 

equals(triggerBody()?['Test']?['value'],true)

 

 

This will return true if ['Test']['value'] is true. Of course, in this case you don't even really need this, as ['Test']['value'] is already a true or false Boolean on its own. You could also just do:

 

 

and(startswith(triggerBody()?['Apple'],'3'),triggerBody()?['Test']?['value'])

 

 

No ", true" required.

 

See if this works - looks fine otherwise

Grayden
Frequent Visitor

I agree with the above reply as a cleaner way of writing this, but that shouldn't be what's holding up your formula.

 

It's that last parenthesis after 'Monkey' that ends your last if too soon, so your first if ends up with 4 args instead of 3. Change your last line from: 

 

if(and(startswith(triggerBody()?['Apple'],'6'),triggerBody()?['Kiwi']?['value'],true),'Monkey'),if(startswith(triggerBody()?['Apple'],'7'),'Monkey'),''))

 

to:

if(and(startswith(triggerBody()?['Apple'],'6'),triggerBody()?['Kiwi']?['value'],true),'Monkey'),if(startswith(triggerBody()?['Apple'],'7'),'Monkey','')))

 

Grayden
Frequent Visitor

This is actually the case with your 2nd and 4th ifs as well, those parentheses need to be moved to the end.

Anonymous
Not applicable

Thank you for your reply. And the others aswell. I did this (also for the 2nd and 4th if) and it works. But now I get a new error!

 

'And always needs boolean parameters. One of them is string'.

 

This sounds weird to me, why does it have to be booleans for an and statement? But for now, how can I change this?

 

Thanks again.

Hi,

 

and() works like an and gate for Boolean values. you need to supply Boolean type arguments. If they all equate to true, the and() expression will also return true. E.g.: and(true, true) would resolve to true.

 

If you want to are comparing several values to others, you do it like this:

 

E.g.: 

and(equals(a, 5), startswith(b,'a'))

 When a = 5 and b starts with 'a', both expressions are true and the and() expression will be true also.

 

Importantly, in PowerAutomate, the and() expression can only take two arguements. You cannot pass 3. 

 

For you, the code should like this:

 

if(and(startswith(triggerBody()?['Apple'],'3'), equals(triggerBody()?['Test']?['value'], true)),
    'Monkey',
    if(and(startswith(triggerBody()?['Apple'],'4'), equals(triggerBody()?['Test']?['value'],true)),
        'Monkey',
        if(and(startswith(triggerBody()?['Apple'],'6'), equals(triggerBody()?['Banana_x003f_']?['value'],true)),
            'Monkey',
            if(and(startswith(triggerBody()?['Apple'],'6'), equals(triggerBody()?['Test']?['value'],true)),
                'Monkey',
                if(and(startswith(triggerBody()?['Apple'],'6'), equals(triggerBody()?['Kiwi']?['value'],true)),
                    'Monkey',
                    if(startswith(triggerBody()?['Apple'],'7'),
                        'Monkey',
                        ''
                    )
                )
            )
        )
    )
)

 

 

View solution in original post

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

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

Users online (1,230)