cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
syhrh
Dual Super User
Dual Super User

Combine Effective Date and Start Date for Holidays Checking

Hi, I have this Holidays list for my Leave Application System. In that list, admin can add new holidays but it also has an effective date that will only commence once today is more or equal to the effective date. I have this apply leave form for the employees and right now it is working well with the StartDate on the Holidays list. Meaning, that if the day they apply for leave is equal to StartDate, it won't count. I would like the checking to be done for the effective date to check whether it is equal to or more than today, only then the StartDate can be counted.

 

anonymous21_1-1661821625715.png

 

This is the formula that includes the StartDate in the Holidays list.

 

I tried this formula but don't know how to combine it with the Holidays from the above formula.

 

 

//App.OnStart
Set(
    checkHolidaysEffectiveDate, 
    First(
        SortByColumns(
            Filter(
                Holidays, 
                'Effective Date' >= Today()
            ), 
        "EffectiveDate", Ascending)
    )
);

 

Thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi, @Anonymous_Hippo sorry for the confusion.

I would like whenever a new holiday is added to the list, it will follow the effective date. Maybe I input the effective date for Children's Day wrong so I updated the Effective Date.

syhrh_1-1662352008823.png

 

What I want to achieve is that the newly added holiday which is Children's Day will commence only on 11 October 2022 because of its effective date. So if the users applied on that day (11 September), it won't count as leave but the leave request needs to be after or on 11 October 2022. If I change the formula,

ClearCollect(ColHolidays,Filter(Holidays,EffectiveDate<=Today()))

 the effective date is less than today. This means that when it's 11 October 2022, the holiday will be added to the collection and I can use the ColHolidays instead of Holidays, right? Is this way work?

View solution in original post

10 REPLIES 10
Anonymous_Hippo
Super User
Super User

Hello @syhrh ,

I would recommend creating a collection to do the effective holiday check . So first step would be to look at all the data from the actual SharePoint list and filter out all the dates that equal to or more than today

 

ClearCollect(ColHolidays,Filter(Holidays,EffectiveDate>=Today()))

 

 

And in your main holidays formula you can utilize data from ColHolidays instead of Holidays. Add this clearCollect in OnStart of App

 

Cheers !

Hi @Anonymous_Hippo,

after I created the collection, it only has one record as the only effective date that is equal to or more than today. So if I change Holidays to ColHolidays, then it will only count 1 record instead of the current fixed holidays on the list.

Hello @syhrh ,

Since we are using Filter function it should give us a table output on whatever that matches your condition. For example i created a test case in my end . My sharepoint list look like this

 

Anonymous_Hippo_1-1662047146477.png

and colHolidays looks like this

 

Anonymous_Hippo_0-1662047138835.png

 

 

Hi @Anonymous_Hippo,

this is my colHolidays

syhrh_0-1662079082188.png

If I change Holidays to colHolidays in my main holidays formula which is on my OnChange.Datacardvalue. Then I would have no Holidays because It only has 1 record and that is not even effective yet. Sorry, I forgot to mention this formula.

Set(
    VarDateDiff, //This variable gives the number of days from today to start date of planned leave- excluding holidays and weekends
    RoundDown(
        DateDiff(
            Today(),
            DataCardValue2.SelectedDate,
            Days
        ) / 7,
        0
    ) * 5 + Mod(
        5 + Weekday(DataCardValue2.SelectedDate) - Weekday(Today()),
        5
    )- CountIf(Holidays, StartDate >= Today(), StartDate <= DataCardValue2.SelectedDate)// this counts the # of holidays falling inbetween Today and Start date
);
If(
    IsBlank(DataCardValue17.SelectedDate),//if End date is not set the show error
    Set(
        VarDateDiff,
        0
    );
    Set(
        VarEndDatenotSetError,
        true
    ),
    Set(
        VarEndDatenotSetError,
        false
    )
);
If(DataCardValue2.SelectedDate >DataCardValue17.SelectedDate,Set(VarStartDateLess,true),Set(VarStartDateLess,false));
If(DataCardValue17.SelectedDate < DataCardValue2.SelectedDate,Set(VarEndDateLess,true),Set(VarEndDateLess,false));

If(
    Weekday(DataCardValue2.SelectedDate) = 7 || Weekday(DataCardValue2.SelectedDate) = 1,
    Set(
        VarDateDiff,
        0
    );
    Set(
        VarWeekEndError,
        true
    ),
    Set(
        VarWeekEndError,
        false
    )
);
If(!IsBlank(LookUp(Holidays,DataCardValue2.SelectedDate=StartDate)) || !IsBlank(LookUp(Holidays,DataCardValue17.SelectedDate=StartDate)),Set(VarHolidayError,true),Set(VarHolidayError,false));
Set(
    VarNegativeDateError,
    If(
        Today() > DataCardValue2.SelectedDate,
        true,
        false
    )
);
Set(
    VarAllowHoliday,
    If(
        VarDateDiff >= Value(checkCondition2),
        true,
        false
    )
);

 

 

Anonymous_Hippo
Super User
Super User

Hello @syhrh  , 

Could you please explain what you are trying to do with an example. Because right now our formula does exactly what you described below. Also if you go through your holiday list, the only effective date greater than equal to today will be children's day. Perhaps you want to do the  reverse


@syhrh

 

 'Effective Date' >= Today() 


Thanks

anonymous21_1-1661821625715.png

@syhrh

@syhrh

Hi, @Anonymous_Hippo sorry for the confusion.

I would like whenever a new holiday is added to the list, it will follow the effective date. Maybe I input the effective date for Children's Day wrong so I updated the Effective Date.

syhrh_1-1662352008823.png

 

What I want to achieve is that the newly added holiday which is Children's Day will commence only on 11 October 2022 because of its effective date. So if the users applied on that day (11 September), it won't count as leave but the leave request needs to be after or on 11 October 2022. If I change the formula,

ClearCollect(ColHolidays,Filter(Holidays,EffectiveDate<=Today()))

 the effective date is less than today. This means that when it's 11 October 2022, the holiday will be added to the collection and I can use the ColHolidays instead of Holidays, right? Is this way work?

Hello @syhrh 

 

Sorry this is still not clear for me. with the above scenario all the holiday's which have an effective date less than or equal to today will be added to the collection ?

 

Can you please tell me which scenario you would like to use?

 

Scenario 1

If you need something to count as holiday only if that date (in the holiday calendar) falls before today, then you don't really need to have an effective date. I do not think it adds any value to do this check ? else could you please tell me why you are trying to do that. Here are you just trying to not count something as a holiday if the holiday is already completed ? for example if holiday 1 is on 1st nov 2022 but this same holday 1 is not in the year 2023 - so are you trying to catch this ?

 

Else

 

Scenario 2

If you need something to count as a holiday only until we are past a certain date. For example Children's day holiday will be only effective once Today is less than September 1st then it makes sense adding a logic for effective date. 

Example: Holiday X 

Start date :11/1/2023

Effective date : 1/1/2023

 

Until we reach 1st January 2023 . If somebody try's to take leave on 1st of November  before January 1st it will be counted as a leave

 

Thanks

 

 

 

 

Hi @Anonymous_Hippo my case is like Scenario 2. That's why I created a column 'Effective Date' and put all past dates for the other holidays except Children's Day. If I create a collection with the formula below,

ClearCollect(ColHolidays,Filter(Holidays,EffectiveDate<=Today()))

all holidays with the Effective Date like 1/1/2020 will be added to the collection and when we reach 1/1/2023 and Holiday X's Effective Date is equal to today then it will also be added to the collection. That's what I'm thinking of doing. Is the logic, right?

 

Thank you.

Hello @syhrh ,

I think your above logic is correct for your need

 

Thanks

 

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors
Users online (4,931)