cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pword
Helper IV
Helper IV

StartDate - End Date leave both holidays but my number of days is counting as 1 day

Hi All,

 

I Have issue with my Leave App, My startdate and End date are both holidays, but my number of days still counting as 1 day. My number of days should be Zero.

 

Please see below

 

w.JPG

 

@StalinPonnusamy 

 

Can you help me with this. Thank you.

 

 

Code :

 

If(varCalculationActive1,
 If(

        Leavetype.Selected.Value = "Maternity leave",
        If(
            StartDates.SelectedDate <= EndDates.SelectedDate,
            DateDiff(
                StartDates.SelectedDate,
                EndDates.SelectedDate,
                Days
            ) + 1 - If(
                Checkbox3.Value,
                0.5
            )
        ),
        (If(
            StartDates.SelectedDate = EndDates.SelectedDate,
            Sum(
                If(
                    Weekday(StartDates.SelectedDate) = 1,
                    0,
                    1
                )
            ) - If(
                Checkbox3.Value,
                0.5
            ),
            If(
                StartDates.SelectedDate > EndDates.SelectedDate,
                -Sum(
                    ForAll(
                        Sequence(
                            DateDiff(
                                EndDates.SelectedDate,
                                StartDates.SelectedDate,
                                Days
                            ),
                            0,
                            1
                        ),
                        If(
                            Weekday(
                                DateAdd(
                                    EndDates.SelectedDate,
                                    Value
                                )
                            ) = 1,
                            {DayCount: 0},
                            {DayCount: 1}
                        )
                    ),
                    DayCount
                ) - If(
                    Checkbox3.Value = false,
                    0.5
                ) - 1/2,
                Sum(
                    ForAll(
                        Sequence(
                            DateDiff(
                                StartDates.SelectedDate,
                                EndDates.SelectedDate,
                                Days
                            ),
                            0,
                            1
                        ),
                        If(
                            Weekday(
                                DateAdd(
                                    StartDates.SelectedDate,
                                    Value
                                )
                            ) = 1,
                            {DayCount: 0},
                            {DayCount: 1}
                        )
                    ),
                    DayCount
                ) + If(
                    Checkbox3.Value = false,
                    0.5
                ) + 1 / 2
            ) - CountRows(
                
                Filter(
                    colHolidays,
                    HolidayDates >= StartDates.SelectedDate,
                    HolidayDates <= EndDates.SelectedDate
                )
            )
        ))
    )
)

 

 

 

 

2 REPLIES 2
EddieE
Solution Sage
Solution Sage

@pword 

In PowerApps, you typically don’t nest If()’s. You use If() like this 

 

If( Condition1, ThenResult1 [, Condition2, ThenResult2, ... [ , DefaultResult ] ] )

 

So just 1 If statement. Try re-writing you logic using this structure and you may find you get what you need? As a tip, I tend to comment my large If statements so that I don’t get lost in the logic … which can easily happen!

 

 

 

v-jefferni
Community Support
Community Support

Hi @pword ,

 

With this kind of situation, you could add a few Labels, copy and paste each parts of the formula and check the results. It's difficult for us to reproduce the issue and find the source.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,639)