web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / trouble with if statement
Power Apps
Unanswered

trouble with if statement

(0) ShareShare
ReportReport
Posted on by 78

im a little lost as to what im doing wrong here (may be something obvious)

 

but with the formula below its meant to set the display mode to disabled if any of the room booked if statements are true .

or if the day is prior to today, or if the lesson finish time is before or equal to the current time 

If(DateAdd(LookUp('week list',week=varCurrweek,'start date'),4)<Today(),DisplayMode.Disabled,
If(DateAdd(LookUp('week list',week=varCurrweek,'start date'),4)=Today(),
If(TimeValue(Text(Now(), "[$-en-GB]hh:mm:ss"))>=TimeValue("18:00"),DisplayMode.Disabled,
If(varcurrentroom="MS-ICT",

 If(First(Filter('MS-ICT','booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),Lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="TrolleyA",

 If(First(Filter(TrolleyA,'booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),Lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="TrolleyB",

 If(First(Filter(TrolleyB,'booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),Lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="TrolleyC",

 If(First(Filter(TrolleyC,'booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),Lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="TrolleyD",

 If(First(Filter(TrolleyD,'booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="TrolleyE",

 If(First(Filter(TrolleyE,'booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="TrolleyF",

 If(First(Filter(TrolleyF,'booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="KS3-laptop-1",

 If(First(Filter('KS3-laptop-1','booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="KS3-laptop-2",

 If(First(Filter('KS3-laptop-2','booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="KS2-laptop-1",

 If(First(Filter('KS2-Laptop-1','booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="Classwatch",

 If(First(Filter(Classwatch,'booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="Sensory-room",

 If(First(Filter('Sensory-room','booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit),

If(varcurrentroom="Outdoor-Gym",

 If(First(Filter('Outdoor-Gym','booked from'= DateAdd(LookUp('week list',week=varCurrweek,'start date'),4),lesson="After School")).booked= true,DisplayMode.Disabled,DisplayMode.Edit)
))))))))))))))))

 

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @daniels471 

    Your formula is too nested to really try and pick it apart for the problems.  Please consider changing your formula to the following:

    With({_startDate: DateAdd(LookUp('week list', week=varCurrweek, 'start date'), 4, Days)},
    
     If(
     (_startDate <Today()) ||
     (_startDate = Today() && (Now() >= Time(18, 0, 0))) ||
     Switch(varcurrentroom,
     "MS-ICT", LookUp('MS-ICT','booked from'= _startDate, Lesson="After School", booked), 
     "TrolleyA", LookUp(TrolleyA,'booked from'= _startDate, Lesson="After School", booked), 
     "TrolleyB", LookUp(TrolleyB,'booked from'= _startDate, Lesson="After School", booked), 
     "TrolleyC", LookUp(TrolleyC,'booked from'= _startDate, Lesson="After School", booked), 
     "TrolleyD", LookUp(TrolleyD,'booked from'= _startDate, lesson="After School", booked), 
     "TrolleyE", LookUp(TrolleyE,'booked from'= _startDate, lesson="After School", booked), 
     "TrolleyF", LookUp(TrolleyF,'booked from'= _startDate, lesson="After School", booked), 
     "KS3-laptop-1", LookUp('KS3-laptop-1','booked from'= _startDate, lesson="After School", booked), 
     "KS3-laptop-2", LookUp('KS3-laptop-2','booked from'= _startDate, lesson="After School", booked), 
     "KS2-laptop-1", LookUp('KS2-Laptop-1','booked from'= _startDate, lesson="After School", booked), 
     "Classwatch", LookUp(Classwatch,'booked from'= _startDate, lesson="After School", booked), 
     "Sensory-room", LookUp('Sensory-room','booked from'= _startDate, lesson="After School", booked), 
     "Outdoor-Gym", LookUp('Outdoor-Gym','booked from'= _startDate, lesson="After School", booked)
     ),
     
     DisplayMode.Disabled,
     DisplayMode.Edit
     )
    )

    This is the same logic that you outlined in your requirement and is much easier to read and maintain. 

     

    Go ahead and put this in place and see where we get with it.  PLEASE NOTE: this was all hand typed without the assistance of the Formula Editor, so there might be some commas or other little things out of place - I tried to visually scrub it as much as possible so that there are no issues, but always a chance.

     

    Going further, if there are still issues with the results, my first inclination would be toward the 'start date' column - it is highly possible that the timezone offset is impacting the evaluations in your formula.  If there is still issue, then we can pick that apart.

     

    I hope this is helpful for you.

  • daniels471 Profile Picture
    78 on at

    hi , I tried that , its getting a lot if issues with the if statements having an invalid number of arguments

     

    im not sure where to start with that as to be honest I'm a little confused by the formula you have came up with  

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @daniels471 

    The formula I have for you should work well. There is most likely a typo or something as I mentioned.

    Can you post a screenshot of the errors you are seeing in the formula?

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @daniels471 

    Trying to re-read through the formula for issues (the screenshot will assist me).  I did notice an issue with the time function.  Here is a replacement formula:

    With({_startDate: DateAdd(LookUp('week list', week=varCurrweek, 'start date'), 4, Days)},
    
     If(
     (_startDate <Today()) ||
     (_startDate = Today() && (Now() >= Today()+Time(18, 0, 0))) ||
     Switch(varcurrentroom,
     "MS-ICT", LookUp('MS-ICT','booked from'= _startDate, Lesson="After School", booked), 
     "TrolleyA", LookUp(TrolleyA,'booked from'= _startDate, Lesson="After School", booked), 
     "TrolleyB", LookUp(TrolleyB,'booked from'= _startDate, Lesson="After School", booked), 
     "TrolleyC", LookUp(TrolleyC,'booked from'= _startDate, Lesson="After School", booked), 
     "TrolleyD", LookUp(TrolleyD,'booked from'= _startDate, lesson="After School", booked), 
     "TrolleyE", LookUp(TrolleyE,'booked from'= _startDate, lesson="After School", booked), 
     "TrolleyF", LookUp(TrolleyF,'booked from'= _startDate, lesson="After School", booked), 
     "KS3-laptop-1", LookUp('KS3-laptop-1','booked from'= _startDate, lesson="After School", booked), 
     "KS3-laptop-2", LookUp('KS3-laptop-2','booked from'= _startDate, lesson="After School", booked), 
     "KS2-laptop-1", LookUp('KS2-Laptop-1','booked from'= _startDate, lesson="After School", booked), 
     "Classwatch", LookUp(Classwatch,'booked from'= _startDate, lesson="After School", booked), 
     "Sensory-room", LookUp('Sensory-room','booked from'= _startDate, lesson="After School", booked), 
     "Outdoor-Gym", LookUp('Outdoor-Gym','booked from'= _startDate, lesson="After School", booked)
     ),
     
     DisplayMode.Disabled,
     DisplayMode.Edit
     )
    )
  • daniels471 Profile Picture
    78 on at

    hi

     

    I have attached a screenshot , it seems to be something with the booked at the end

     

    powerapps error.png

     

  • Verified answer
    daniels471 Profile Picture
    78 on at

    hi , I seem to have solved it ( hopefully), by changing to the following formula

    With({_startDate: DateAdd(LookUp('week list', week=varCurrweek, 'start date'), 4, Days)},
    
     If(
     (_startDate <Today()) ||
     (_startDate = Today() && (Now() >= Today()+Time(18, 0, 0))) ||
     Switch(varcurrentroom,
     "MS-ICT", LookUp('MS-ICT','booked from'= _startDate && Lesson="After School", booked),
     "TrolleyA", LookUp(TrolleyA,'booked from'= _startDate && Lesson="After School", booked), 
     "TrolleyB", LookUp(TrolleyB,'booked from'= _startDate && Lesson="After School", booked), 
     "TrolleyC", LookUp(TrolleyC,'booked from'= _startDate && Lesson="After School", booked), 
     "TrolleyD", LookUp(TrolleyD,'booked from'= _startDate && lesson="After School", booked), 
     "TrolleyE", LookUp(TrolleyE,'booked from'= _startDate && lesson="After School", booked), 
     "TrolleyF", LookUp(TrolleyF,'booked from'= _startDate && lesson="After School", booked), 
     "KS3-laptop-1", LookUp('KS3-laptop-1','booked from'= _startDate && lesson="After School", booked), 
     "KS3-laptop-2", LookUp('KS3-laptop-2','booked from'= _startDate && lesson="After School", booked), 
     "KS2-laptop-1", LookUp('KS2-Laptop-1','booked from'= _startDate && lesson="After School", booked), 
     "Classwatch", LookUp(Classwatch,'booked from'= _startDate && lesson="After School", booked), 
     "Sensory-room", LookUp('Sensory-room','booked from'= _startDate && lesson="After School",booked), 
     "Outdoor-Gym", LookUp('Outdoor-Gym','booked from'= _startDate && lesson="After School",booked)
     ),
     
     DisplayMode.Disabled,
     DisplayMode.Edit
     )
    )

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard