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

Combine If statements

Hi there, 

I am in the situation that i have two If Statements that works very well individually, however i would like to combine them in a way that powerapps would be able to check both parameters before returning true;false or in this case Disabled;Edit. 

1. 

If(TimeValue(Text(Now()))>Time(09,45,00),Disabled,Edit)
//Decides whether a button should be pressable based on the current time of the day, in this case whether the time has surpassed 09:45, if yes, disable if no, edit. 

 

2.

If(Weekday(Now(),Monday)>=3,Disabled,Edit)
/7Checks if the dau has surpassed a specific day of the week, in this case wednesday, and decides whether the button should be editable based on this. 

These are the two statements thatI would like to combine into one statement, in order for powerapps to check both things before  returning. So that it would be able to disable a button if the time has surpassed 0945 on a monday but leave another editable until 0945 on wednesday. 

Essentially first check what day it is (1-7) and then check the time and return a value. 

hope you can help. 
- Tobias 

2 ACCEPTED SOLUTIONS

Accepted Solutions
yashag2255
Dual Super User II
Dual Super User II

Hey @Anonymous 

 

can you try to combine the expressions as:
 
If(TimeValue(Text(Now()))>Time(09,45,00) && Weekday(Now(),Monday)>=3,Disabled,Edit)
 
Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

chrisog
Responsive Resident
Responsive Resident

Hi @Anonymous,

 

Just to explain @yashag2255's answer a bit, there is the And() function, which only returns true when all statements are satisfied as true within it. The && operator is just a different way to say the same thing.

 

If(TimeValue(Text(Now()))>Time(09,45,00) && Weekday(Now(),Monday)>=3,Disabled,Edit) 

is the same as 

If(And(TimeValue(Text(Now()))>Time(09,45,00),Weekday(Now(),Monday)>=3),Disabled,Edit)

 

There is also the Or() function, or ||, returns true when any of the statements are true.

 

Finally, there is Not(), or !, which inverts the result. The ! must precede the statement you want to invert. You can place it before individual statements or before the And() and Or() functions to invert the entire result.

View solution in original post

4 REPLIES 4
yashag2255
Dual Super User II
Dual Super User II

Hey @Anonymous 

 

can you try to combine the expressions as:
 
If(TimeValue(Text(Now()))>Time(09,45,00) && Weekday(Now(),Monday)>=3,Disabled,Edit)
 
Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

chrisog
Responsive Resident
Responsive Resident

Hi @Anonymous,

 

Just to explain @yashag2255's answer a bit, there is the And() function, which only returns true when all statements are satisfied as true within it. The && operator is just a different way to say the same thing.

 

If(TimeValue(Text(Now()))>Time(09,45,00) && Weekday(Now(),Monday)>=3,Disabled,Edit) 

is the same as 

If(And(TimeValue(Text(Now()))>Time(09,45,00),Weekday(Now(),Monday)>=3),Disabled,Edit)

 

There is also the Or() function, or ||, returns true when any of the statements are true.

 

Finally, there is Not(), or !, which inverts the result. The ! must precede the statement you want to invert. You can place it before individual statements or before the And() and Or() functions to invert the entire result.

View solution in original post

Anonymous
Not applicable

@chrisog @yashag2255 

I was so close to getting there myself, i just needed to switch a few things, but this makes perfect sense thank you so much! 

Anonymous
Not applicable

@chrisog @yashag2255 

Hi again, 

It does not really seem to work, i have tried 

 

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)

 

In all cases it should check if the date is tuesday 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? 

Do you have any suggestions on how to optimize this or why this error might occur, or is it simply just not possible to create this function within PowerApps 🙂 

- Tobi 

 

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

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.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,607)