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

trouble with if statement

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)
))))))))))))))))

 

1 ACCEPTED SOLUTION

Accepted Solutions

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
  )
)

View solution in original post

6 REPLIES 6
RandyHayes
Super User III
Super User III

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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
Super User III
Super User III

@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?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
RandyHayes
Super User III
Super User III

@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
  )
)
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
daniels471
Helper II
Helper II

hi

 

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

 

powerapps error.png

 

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
  )
)

View solution in original post

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,234)