cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
TCH
Level: Powered On

If statements(Multiple conditions)

Hi guys, 

I am trying to make an app in which I have checkboxes that needs to be "disabled" at specific points, the idea is that in all cases(below) it should check if the date is tuesday(these are present in the app for all weekdays) and whether the time is before or after 0930, and then return true or false based on both these coniditions. However, it does not really do this, it only checks for the first condition and then it sort of fails to check the other one, meaning that today friday, if I set any of the above functions with the time condition first to 1030 it will only check for this and return true, it does not take into acount whether it is also tuesday or not, of course this function should be disabled from wednesday on, until monday where a new week begins? 

 

If(And(TimeValue(Text(Now()))>Time(09;30;00);Weekday(Now();Monday)>=2);Disabled;Edit)



If(TimeValue(Text(Now()))>Time(09;30;00) && Weekday(Now();Monday)>=2;Disabled;Edit)



If(TimeValue(Text(Now()))>Time(09;30;00) && Weekday(Now();Monday)>=2;Disabled;Edit)

 

 

If(Weekday(Now();Monday)>=2;Disabled;Edit && TimeValue(Text(Now()))>Time(09;30;00))



If(Weekday(Now();Monday)>=2 && TimeValue(Text(Now()))>Time(09;30;00);Disabled;Edit)


Does anyone have any suggestions on how to optimize/solve this or why this error might occur, or is it simply just not possible to create this function within PowerApps?

- Tobi 

1 ACCEPTED SOLUTION

Accepted Solutions
chrisog
Level 8

Re: If statements(Multiple conditions)

@TCH 

 

I think I know what the problem is! The logic is telling it only to disable the checkboxes when both tests return true, not when either do. What you need is a combination of And and Or.

 

Try this for your Tuesday checkbox, for example:

 

If(Or(Weekday(Today();Monday)<2, And(Weekday(Today();Monday)=2,TimeValue(Text(Now()))>Time(09,30,00))),Disabled, Edit)

 

What this does it check whether either of the 2 OR statement return true, and one of those statements is the And statement.

 

Firstly, it checks whether today is less than tuesday. If so, return true and disable the checkbox. If not, it checks if today is tuesday and the time is after 9:30. If true, disable the checkbox. If neither of those OR conditions are true, do not disable the checkbox. 

 

Your workaround probably would work with a bit of work but I think this is just a matter of the logic being wrong in the IF statement. 

 

For future reference, LookUp works like the following:

 

LookUp( DataSourceToLookUp, LogicalTest, Result)

 

For instance:

 

LookUp(MyData, DateColumn = Today(), Username) would search the table MyData for the first value of Today() in DateColumn and return the value in the same row in the Username column.

 

If you need any more help feel free to send me a message and I can try to help wherever I can.

View solution in original post

7 REPLIES 7
chrisog
Level 8

Re: If statements(Multiple conditions)

Hi @TCH,

 

I have tested this:

 

If(And(TimeValue(Text(Now()))>Time(09,30,00),Weekday(Today(),Monday)>=2),Disabled,Edit)

 

on my end and it works perfectly. I could change the conditions for different results too. I'm not sure why this isn't working for you. Is there an error message or warning that appears when you input the formula?

 

Stupid question but are you definitely putting this in the correct property?

TCH
Level: Powered On

Re: If statements(Multiple conditions)

@chrisog 

It is really strange, but no there is not any error message popping up. The code is attached to the "DisplayMode" property of the given checkbox? that surely is the correct property no? 

The funny thing is that now, after 0930(Denmark) it works absolutely fine, however before 0930 it does not. I have checkboxes for each day Monday - Sunday, so today(Tuesday) the Monday checkbox should be disabled the entire day, it should be disabled from Monday 0930 and the rest of the week, however it won't do this if the time is before the "disable time" in this case 0930, before this time it will not disable Monday, even though its Tuesday and it should be disabled? make sense? 🙂 

- Tobi 

chrisog
Level 8

Re: If statements(Multiple conditions)

Yeah that's the right property. I assumed you had it right but you have to ask, you know?

 

So as an alternative could you try:

 

If(And(TimeValue(Text(Now()))>Time(09,30,00),Weekday(Today(),Monday)<>2),Disabled,Edit)

 

I have changed the operator for the weekday test to <>, which means does not equal. This means it should always return false if the weekday does not equal, in the case above, tuesday.

 

Do i have it correct that you want Wednesday's checkbox to be disabled on a tuesday too? If so, the above should work. 

 

 

You could also try something like If(And(Text(Today(),"dddd") = "Tuesday",TimeValue(Text(Now()))<Time(09,30,00)))

TCH
Level: Powered On

Re: If statements(Multiple conditions)

@chrisog 

Yeah of course, I would have asked to 🙂 

Yeah so this would disable it all days that it was not Tuesday for example. 

However, what i am hoping to achieve is to follow the week chronologically, so: 

Monday pre 0930: every checkbox is enabled. 
Monday post 0930: Tuesday, Wednesday, Thursday, Friday is enabled. 
Tuesday pre 0930: Tuesday, Wednesday, Thursday, Friday is enabled. 
Tuesday post 0930: Wednesday, Thursday, Friday is enabled. 
Wednesday pre 0930: Wednesday, Thursday, Friday is enabled. 
Wednesday post 0930 Thursday & Friday is enabled. 
etc. 

So that it should be disabled if the time has passed 0930 on that day, Wednesday checkbox should disable at 0930 Wednesday, and only enable again the next monday, however it should not be disabled on Monday and Tuesday 🙂 

Hope this makes sense. 



TCH
Level: Powered On

Re: If statements(Multiple conditions)

@chrisog   

Just a possible workaround, that maybe you can help with, i am a fairly new to powerapps, so maybe this is a wild idea, but here goes 🙂 

As i said, if the time is after 0930 it understands perfectly well which checboxes should be enabled and disabled, and this is sort of fine. The main reason for this being neccessary is so that people can't call a patch function twice for the same day. 

Right now it looks like this(Monday Example): 

If('Monday()'.Value= true;
   Set(gblItemPatched;Patch(Monday;Defaults(Monday);{Title:User().FullName;WorkID:WID.Text;Date: Date.Text})))

 So it checks whether one has ticked of the Monday checkbox, and then if they have it will patch their information to a SharePoint List. However, is there a way to make it check if the persons details(name etc, so their patched information) is already present in that SharePoint list and then tell it to ignore the call to patch if this is true? This would disable people from ordering twice even if the checkboxes are not disabled 🙂 

I know there is a LookUp function, but i am not sure how to apply this in practice, is this something you have any experience with 🙂 

- Tobi 

chrisog
Level 8

Re: If statements(Multiple conditions)

@TCH 

 

I think I know what the problem is! The logic is telling it only to disable the checkboxes when both tests return true, not when either do. What you need is a combination of And and Or.

 

Try this for your Tuesday checkbox, for example:

 

If(Or(Weekday(Today();Monday)<2, And(Weekday(Today();Monday)=2,TimeValue(Text(Now()))>Time(09,30,00))),Disabled, Edit)

 

What this does it check whether either of the 2 OR statement return true, and one of those statements is the And statement.

 

Firstly, it checks whether today is less than tuesday. If so, return true and disable the checkbox. If not, it checks if today is tuesday and the time is after 9:30. If true, disable the checkbox. If neither of those OR conditions are true, do not disable the checkbox. 

 

Your workaround probably would work with a bit of work but I think this is just a matter of the logic being wrong in the IF statement. 

 

For future reference, LookUp works like the following:

 

LookUp( DataSourceToLookUp, LogicalTest, Result)

 

For instance:

 

LookUp(MyData, DateColumn = Today(), Username) would search the table MyData for the first value of Today() in DateColumn and return the value in the same row in the Username column.

 

If you need any more help feel free to send me a message and I can try to help wherever I can.

View solution in original post

TCH
Level: Powered On

Re: If statements(Multiple conditions)

@chrisog 

That makes perfect sense! And it works like a charm :)! thank you! 🙂 

I think I will play around with the lookup function, I will definately message you if needed, thanks very much for the help 🙂 

- Tobi 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 204 members 6,377 guests
Please welcome our newest community members: