cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ljkeefe
Resolver I
Resolver I

DATEDIFF variable not calculating correctly

Just when I solve one issue with this app, I discover another.

I created an app with several date pickers that calculate dates in reverse. I had to create a variable for the final date picker because its date would be contingent on its own date and the deadline of the meeting before that, thus would give me a circular reference error.

The problem is that the variable calculates the days in between the deadline and the meeting date correctly but when I check the variable in the IF statement of the date picker I need the date to generate on, the days are wrong.

The example below shows a 1 day difference between the two circled dates, which shows correctly in the Set function.

Set(varP, DateDiff( MeetingA.SelectedDate,MeetingB.SelectedDate,Days))

ljkeefe_0-1653598483607.png

But shows a much larger number in the IF statement of Meeting A date picker. If I highlight varP, it shows me it's calculating 6 days.

If(IsBlank(MeetingB),"",varP<=6,PrevThirdMon,PrevFourthMon)))))))))))))

 Please help. Thanks!

2 ACCEPTED SOLUTIONS

Accepted Solutions
iAm_ManCat
Most Valuable Professional
Most Valuable Professional

Len vs IsBlank? Experience 😞

I have been caught too many times where IsBlank is considered 'technically false' because of a partial or previous value still being looked at, whereas Len always calculates the current Length of the item at the current moment in time, which should be zero if it's truly blank.

 

For varP, I can't say for certain but I think the defaultDate is still looking at the previous value of varP, so we could try using the direct datediff comparison instead of the variable?

 

With({
        PrevFirstOfMonth: Date(Year(MeetingB.SelectedDate), Month(DateAdd(MeetingB.SelectedDate, -1, Months)), 1),
        WholeWeek: 7
    },
    With({
            DayOfWeekPrevFirstOfMonth: Weekday(PrevFirstOfMonth, StartOfWeek.Tuesday)
        },
        With({
                PrevFirstMonday: DateAdd(PrevFirstOfMonth, (1 * WholeWeek) - (DayOfWeekPrevFirstOfMonth))
            },
            With({
                    PrevThirdMonday: DateAdd(PrevFirstMonday, WholeWeek * 2),
                    PrevFourthMonday: DateAdd(PrevFirstMonday, WholeWeek * 3)
                },
                If( Len(MeetingB.SelectedDate)=0,
                    "", 
                    DateDiff( MeetingA.SelectedDate, MeetingB.SelectedDate,Days) <= 6, 
                    PrevThirdMonday,
                    PrevFourthMonday
                )
            )
        )
    )
)

 


@iAm_ManCat
My blog


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


View solution in original post

@iAm_ManCat I figured it out by removing the variable varP and replacing it with a DateDiff statement using the PrevFourthMonday WITH variable. Here was the final expression:

With(
    {
        PrevFirstOfMonth: Date(
            Year(MeetingB.SelectedDate),
            Month(
                DateAdd(
                    MeetingB.SelectedDate,
                    -1,
                    Months
                )
            ),
            1
        ),
        WholeWeek: 7
    },
    With(
        {
            DayOfWeekPrevFirstOfMonth: Weekday(
                PrevFirstOfMonth,
                StartOfWeek.Tuesday
            )
        },
        With(
            {
                PrevFirstMonday: DateAdd(
                    PrevFirstOfMonth,
                    (1 * WholeWeek) - (DayOfWeekPrevFirstOfMonth)
                )
            },
            With(
                {
                    PrevThirdMonday: DateAdd(
                        PrevFirstMonday,
                        WholeWeek * 2
                    ),
                    PrevFourthMonday: DateAdd(
                        PrevFirstMonday,
                        WholeWeek * 3
                    )
                },
                If(
                    Len(MeetingB.SelectedDate) = 0,
                    "",
                    DateDiff(PrevFourthMonday,MeetingB.SelectedDate) <= 6,
                    PrevThirdMonday,
                    PrevFourthMonday
                )
            )
        )
    )
)

 Thank you so much for your help!! 

View solution in original post

12 REPLIES 12
iAm_ManCat
Most Valuable Professional
Most Valuable Professional

Hi @ljkeefe,

 

Are you setting varP on the Onchange of both datepickers?

What creates the PrevThirdMon and can we see the code for that? There's a lot of moving parts here so you'll need to share more for us to help (judging by the crazy number of closing brackets in your second snippet)


@iAm_ManCat
My blog


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Hi @iAm_ManCat ,

 

Thank you for the response and apologies for the delay, I was on vacation! I never know how much or how little information to provide but here it goes.

The varP variable is set on the OnChange property of the "Approved by" date picker under Meeting B. That Meeting B "Approved by" date picker has the following under Default Date:

If(IsBlank(MeetingB.SelectedDate),"",DateAdd(MeetingB.SelectedDate,-6,Days))

The OnChange property of Meeting B "Approved by" date picker is:

Set(varP, DateDiff( MeetingA.SelectedDate,MeetingB.SelectedDate,Days))

ljkeefe_0-1654541251454.png

Meeting A date picker has the following on DefaultDate property, forgive all the WITH statements but it's the only way I could figure out how to do this: 

With({FirstMonth:Date(Year(MeetingB.SelectedDate),Month(MeetingB.SelectedDate),1),DayOfWeek1:2,N1:1},With({FirstMonday:DateAdd(FirstMonth,(N1 * 7) - Weekday(DateAdd(FirstMonth,7-DayOfWeek1)))},

With({SecondOfMonthP:Date(Year(MeetingB.SelectedDate),Month(MeetingB.SelectedDate),1),
DayOfWeek2:2,N2:2},With({SecondMonday:DateAdd(SecondOfMonthP,(N2*7)-Weekday(DateAdd(SecondOfMonthP,7-DayOfWeek2)))},
With({ThirdOfMonthP:Date(Year(MeetingB.SelectedDate),Month(MeetingB.SelectedDate),1),DayofWeek3:2,N3:3},With({ThirdMonday3:DateAdd(ThirdOfMonthP,(N3*7)-Weekday(DateAdd(ThirdOfMonthP,7-DayofWeek3)))},
With({FourthOfMonthP:Date(Year(MeetingB.SelectedDate),Month(MeetingB.SelectedDate),1),DayofWeek4:2,N4:4},With({FourthMondayP:DateAdd(FourthOfMonthP,(N4*7)-Weekday(DateAdd(FourthOfMonthP,7-DayofWeek4)))}, 
With({PrevFourth: Date(Year(MeetingB.SelectedDate),Month(MeetingB.SelectedDate),1),DOW:2,N:1}, 
With({PrevFourthMon:  DateAdd(DateAdd(PrevFourth,-1,Months),(N4*7) - Weekday(DateAdd(PrevFourth,7-DOW)))},
With({PrevThirdMon: DateAdd(DateAdd(PrevFourth,-1,Months),(N3*7) - Weekday(DateAdd(PrevFourth,7-DOW)))},


If(IsBlank(MeetingB),"",varP<=6,PrevThirdMon,PrevFourthMon))))))))))))

 

The OTHER issue aside from my varP variable not calculating correctly is that the days of the week calculated by the WITH statement are off. As you can see in the various WITH statements above DayOftheWeek is set to 2 for Monday, the N is the week of the month. Since I'm counting backward, I thought to reverse the number for the days so Monday instead of 2 become 6, but that didn't work either. 

Your help is appreciated.

 

 

iAm_ManCat
Most Valuable Professional
Most Valuable Professional

Ok, well let's break this down, we can refactor your code a bit. Sorry for the long explanation (please view this in the browser and not in your email), I will try to help you understand how to do less With and how to refactor your code into simpler terms. You can skip to the end for the answer if you want but I do recommend trying to understand it a bit more

 

Firstly, we neaten it up so we can see where everything is:

 

With({
    FirstMonth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
    DayOfWeek1: 2,
    N1: 1
    }, 
    With({
        FirstMonday: DateAdd(FirstMonth, (N1 * 7) - Weekday(DateAdd(FirstMonth, 7 - DayOfWeek1)))
        },
        With({
            SecondOfMonthP: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
            DayOfWeek2: 2,
            N2: 2
            }, 
            With({
                    SecondMonday: DateAdd(SecondOfMonthP, (N2 * 7) - Weekday(DateAdd(SecondOfMonthP, 7 - DayOfWeek2)))
                },
                With({
                    ThirdOfMonthP: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
                    DayofWeek3: 2,
                    N3: 3
                    }, 
                    With({
                            ThirdMonday3: DateAdd(ThirdOfMonthP, (N3 * 7) - Weekday(DateAdd(ThirdOfMonthP, 7 - DayofWeek3)))
                        },
                        With({
                            FourthOfMonthP: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
                            DayofWeek4: 2,
                            N4: 4
                            }, 
                            With({
                                    FourthMondayP: DateAdd(FourthOfMonthP, (N4 * 7) - Weekday(DateAdd(FourthOfMonthP, 7 - DayofWeek4)))
                                },
                                With({
                                        PrevFourth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
                                        DOW: 2,
                                        N: 1
                                    },
                                    With({
                                            PrevFourthMon: DateAdd(DateAdd(PrevFourth, -1, Months), (N4 * 7) - Weekday(DateAdd(PrevFourth, 7 - DOW)))
                                        },
                                        With({
                                                PrevThirdMon: DateAdd(DateAdd(PrevFourth, -1, Months), (N3 * 7) - Weekday(DateAdd(PrevFourth, 7 - DOW)))
                                            },
                                            If(IsBlank(MeetingB), "", varP <= 6, PrevThirdMon, PrevFourthMon)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
)

 

 

Next, I see that your day of week: 2 is the same everywhere, so we can re-use the original dayofweek1:

 

 

With({
    FirstMonth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
    DayOfWeek1: 2,
    N1: 1
    }, 
    With({
        FirstMonday: DateAdd(FirstMonth, (N1 * 7) - Weekday(DateAdd(FirstMonth, 7 - DayOfWeek1)))
        },
        With({
            SecondOfMonthP: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
            N2: 2
            }, 
            With({
                    SecondMonday: DateAdd(SecondOfMonthP, (N2 * 7) - Weekday(DateAdd(SecondOfMonthP, 7 - DayOfWeek1)))
                },
                With({
                    ThirdOfMonthP: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
                    N3: 3
                    }, 
                    With({
                            ThirdMonday3: DateAdd(ThirdOfMonthP, (N3 * 7) - Weekday(DateAdd(ThirdOfMonthP, 7 - DayOfWeek1)))
                        },
                        With({
                            FourthOfMonthP: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
                            N4: 4
                            }, 
                            With({
                                    FourthMondayP: DateAdd(FourthOfMonthP, (N4 * 7) - Weekday(DateAdd(FourthOfMonthP, 7 - DayOfWeek1)))
                                },
                                With({
                                        PrevFourth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
                                        N: 1
                                    },
                                    With({
                                            PrevFourthMon: DateAdd(DateAdd(PrevFourth, -1, Months), (N4 * 7) - Weekday(DateAdd(PrevFourth, 7 - DayOfWeek1)))
                                        },
                                        With({
                                                PrevThirdMon: DateAdd(DateAdd(PrevFourth, -1, Months), (N3 * 7) - Weekday(DateAdd(PrevFourth, 7 - DayOfWeek1)))
                                            },
                                            If(IsBlank(MeetingB), "", varP <= 6, PrevThirdMon, PrevFourthMon)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
)

 

 

Then we can take out the N1 and etc and just use 1,2,3 etc:

 

With({
    FirstMonth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
    DayOfWeek1: 2
    }, 
    With({
        FirstMonday: DateAdd(FirstMonth, (1 * 7) - Weekday(DateAdd(FirstMonth, 7 - DayOfWeek1)))
        },
        With({
            SecondOfMonthP: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
            }, 
            With({
                    SecondMonday: DateAdd(SecondOfMonthP, (2 * 7) - Weekday(DateAdd(SecondOfMonthP, 7 - DayOfWeek1)))
                },
                With({
                    ThirdOfMonthP: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
                    }, 
                    With({
                            ThirdMonday3: DateAdd(ThirdOfMonthP, (3 * 7) - Weekday(DateAdd(ThirdOfMonthP, 7 - DayOfWeek1)))
                        },
                        With({
                            FourthOfMonthP: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
                            }, 
                            With({
                                    FourthMondayP: DateAdd(FourthOfMonthP, (4 * 7) - Weekday(DateAdd(FourthOfMonthP, 7 - DayOfWeek1)))
                                },
                                With({
                                        PrevFourth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
                                    },
                                    With({
                                            PrevFourthMon: DateAdd(DateAdd(PrevFourth, -1, Months), (4 * 7) - Weekday(DateAdd(PrevFourth, 7 - DayOfWeek1)))
                                        },
                                        With({
                                                PrevThirdMon: DateAdd(DateAdd(PrevFourth, -1, Months), (3 * 7) - Weekday(DateAdd(PrevFourth, 7 - DayOfWeek1)))
                                            },
                                            If(IsBlank(MeetingB), "", varP <= 6, PrevThirdMon, PrevFourthMon)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
)

 

 

Then I can see that your FirstMonth, SecondOfMonthP, ThirdOfMonthP, FourthOfMonthP and PrevFourth all use the exact same formula, so we can just refer to FirstMonth in each of those cases:

 

 

With({
    FirstMonth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
    DayOfWeek1: 2
    }, 
    With({
        FirstMonday: DateAdd(FirstMonth, (1 * 7) - Weekday(DateAdd(FirstMonth, 7 - DayOfWeek1)))
        },
        With({
            }, 
            With({
                    SecondMonday: DateAdd(FirstMonth, (2 * 7) - Weekday(DateAdd(FirstMonth, 7 - DayOfWeek1)))
                },
                With({
                    }, 
                    With({
                            ThirdMonday3: DateAdd(FirstMonth, (3 * 7) - Weekday(DateAdd(FirstMonth, 7 - DayOfWeek1)))
                        },
                        With({
                            }, 
                            With({
                                    FourthMondayP: DateAdd(FirstMonth, (4 * 7) - Weekday(DateAdd(FirstMonth, 7 - DayOfWeek1)))
                                },
                                With({
                                    },
                                    With({
                                            PrevFourthMon: DateAdd(DateAdd(FirstMonth, -1, Months), (4 * 7) - Weekday(DateAdd(FirstMonth, 7 - DayOfWeek1)))
                                        },
                                        With({
                                                PrevThirdMon: DateAdd(DateAdd(FirstMonth, -1, Months), (3 * 7) - Weekday(DateAdd(FirstMonth, 7 - DayOfWeek1)))
                                            },
                                            If(IsBlank(MeetingB), "", varP <= 6, PrevThirdMon, PrevFourthMon)
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
)

 

 

Now we don't need all of those With statements as only the last section relies on any of the other values:

 

With({
    FirstMonth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
    DayOfWeek1: 2
    }, 
    With({
        FirstMonday:   DateAdd( FirstMonth, (1 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))),
        SecondMonday:  DateAdd( FirstMonth, (2 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))),
        ThirdMonday3:  DateAdd( FirstMonth, (3 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))),
        FourthMondayP: DateAdd( FirstMonth, (4 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))),
        PrevFourthMon: DateAdd( DateAdd( FirstMonth, -1, Months), (4 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))),
        PrevThirdMon:  DateAdd( DateAdd( FirstMonth, -1, Months), (3 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1)))
        },
        If(IsBlank(MeetingB), "", varP <= 6, PrevThirdMon, PrevFourthMon)
    )
)

 

 

Now we should also fix that we are referencing a control directly, so IsBlank MeetingB becomes Len(MeetingB.SelectedDate)=0

 

With({
    FirstMonth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
    DayOfWeek1: 2
    }, 
    With({
        FirstMonday:   DateAdd( FirstMonth, (1 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))),
        SecondMonday:  DateAdd( FirstMonth, (2 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))),
        ThirdMonday3:  DateAdd( FirstMonth, (3 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))),
        FourthMondayP: DateAdd( FirstMonth, (4 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))),
        PrevFourthMon: DateAdd( DateAdd( FirstMonth, -1, Months), (4 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))),
        PrevThirdMon:  DateAdd( DateAdd( FirstMonth, -1, Months), (3 * 7) - Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1)))
        },
        If(Len(MeetingB.SelectedDate)=0, "", varP <= 6, PrevThirdMon, PrevFourthMon)
    )
)

 

 

Then I can see you are using the same Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1)) code in a few places so we can make that a variable called WeekdayMinus:

 

With({
    FirstMonth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
    DayOfWeek1: 2
    },
    With({
         WeekdayMinus: Weekday( DateAdd( FirstMonth, 7 - DayOfWeek1))
        },
        With({
            FirstMonday:   DateAdd( FirstMonth, (1 * 7) - WeekdayMinus),
            SecondMonday:  DateAdd( FirstMonth, (2 * 7) - WeekdayMinus),
            ThirdMonday3:  DateAdd( FirstMonth, (3 * 7) - WeekdayMinus),
            FourthMondayP: DateAdd( FirstMonth, (4 * 7) - WeekdayMinus),
            PrevFourthMon: DateAdd( DateAdd( FirstMonth, -1, Months), (4 * 7) - WeekdayMinus),
            PrevThirdMon:  DateAdd( DateAdd( FirstMonth, -1, Months), (3 * 7) - WeekdayMinus)
            },
            If(Len(MeetingB.SelectedDate)=0, "", varP <= 6, PrevThirdMon, PrevFourthMon)
        )
    )
)

 

 

Then I can see you referring to the previous first of month at the end so lets make that a variable:

 

With({
    FirstMonth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
    PrevFirstMonth: Date(Year(MeetingB.SelectedDate), Month(DateAdd( MeetingB.SelectedDate, -1, Months)), 1),
    DayOfWeek: Weekday(MeetingB.SelectedDate),
    },
    With({
         WeekdayMinus: Weekday( DateAdd( FirstMonth, 7 - DayOfWeek))
        },
        With({
            FirstMonday:   DateAdd(     FirstMonth, (1 * 7) - WeekdayMinus),
            SecondMonday:  DateAdd(     FirstMonth, (2 * 7) - WeekdayMinus),
            ThirdMonday3:  DateAdd(     FirstMonth, (3 * 7) - WeekdayMinus),
            FourthMondayP: DateAdd(     FirstMonth, (4 * 7) - WeekdayMinus),

            PrevFourthMon: DateAdd( PrevFirstMonth, (4 * 7) - WeekdayMinus),
            PrevThirdMon:  DateAdd( PrevFirstMonth, (3 * 7) - WeekdayMinus)
            },
            If(Len(MeetingB.SelectedDate)=0, "", varP <= 6, PrevThirdMon, PrevFourthMon)
        )
    )
)

 

 

Now we can expand that a bit to get a formula we can put in a label to see all of the debug values after I've tweaked it a bit:

 

With({
        FirstOfMonth: Date(Year(MeetingB.SelectedDate), Month(MeetingB.SelectedDate), 1),
        PrevFirstOfMonth: Date(Year(MeetingB.SelectedDate), Month(DateAdd(MeetingB.SelectedDate, -1, Months)), 1),
        WholeWeek: 7
    },
    With({
            DayOfWeekFirstOfMonth: Weekday(FirstOfMonth, StartOfWeek.Tuesday),
            DayOfWeekPrevFirstOfMonth: Weekday(PrevFirstOfMonth, StartOfWeek.Tuesday)
        },

        With({
                FirstMonday: DateAdd(FirstOfMonth, (1 * WholeWeek) - (DayOfWeekFirstOfMonth)),
                PrevFirstMonday: DateAdd(PrevFirstOfMonth, (1 * WholeWeek) - (DayOfWeekPrevFirstOfMonth))
            },
            With({

                    SecondMonday: DateAdd(FirstMonday, WholeWeek * 1),
                    ThirdMonday: DateAdd(FirstMonday, WholeWeek * 2),
                    FourthMonday: DateAdd(FirstMonday, WholeWeek * 3),
                    PrevSecondMonday: DateAdd(PrevFirstMonday, WholeWeek * 1),
                    PrevThirdMonday: DateAdd(PrevFirstMonday, WholeWeek * 2),
                    PrevFourthMonday: DateAdd(PrevFirstMonday, WholeWeek * 3)
                },

                If(true,
                    //Len(MeetingB.SelectedDate)=0, "", varP <= 6, 
                    //PrevThirdMon, PrevFourthMon

                    "FirstOfMonth " & FirstOfMonth & Char(10) &
                    "DayOfWeekFirstOfMonth " & DayOfWeekFirstOfMonth & Char(10) &
                    "FirstMonday " & FirstMonday & Char(10) &
                    "SecondMonday " & SecondMonday & Char(10) &
                    "ThirdMonday " & ThirdMonday & Char(10) &
                    "FourthMonday " & FourthMonday & Char(10) &
                    "PrevFirstOfMonth " & PrevFirstOfMonth & Char(10) &
                    "DayOfWeekPrevFirstOfMonth " & DayOfWeekPrevFirstOfMonth & Char(10) &
                    "PrevFirstMonday " & PrevFirstMonday & Char(10) &
                    "PrevSecondMonday " & PrevSecondMonday & Char(10) &
                    "PrevThirdMonday " & PrevThirdMonday & Char(10) &
                    "PrevFourthMonday " & PrevFourthMonday & Char(10)

                )

            )
        )
    )
)

 

The above should help you understand how the date math works a little better,

 

Then finally, you can use this as your defaultdate (since you dont use the original first second etc dates):

With({
        PrevFirstOfMonth: Date(Year(MeetingB.SelectedDate), Month(DateAdd(MeetingB.SelectedDate, -1, Months)), 1),
        WholeWeek: 7
    },
    With({
            DayOfWeekPrevFirstOfMonth: Weekday(PrevFirstOfMonth, StartOfWeek.Tuesday)
        },
        With({
                PrevFirstMonday: DateAdd(PrevFirstOfMonth, (1 * WholeWeek) - (DayOfWeekPrevFirstOfMonth))
            },
            With({
                    PrevThirdMonday: DateAdd(PrevFirstMonday, WholeWeek * 2),
                    PrevFourthMonday: DateAdd(PrevFirstMonday, WholeWeek * 3)
                },
                If( Len(MeetingB.SelectedDate)=0, "", 
                    varP <= 6, 
                    PrevThirdMonday,
                    PrevFourthMonday
                )
            )
        )
    )
)

 


@iAm_ManCat
My blog


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


@iAm_ManCat Oh my goodness, thank you! That is so much more digestible. I really appreciate you breaking it down for me.

Two problems/questions:

1. I don't understand why you use LEN vs. ISBLANK

2. My varP is still not calculating correctly. 

ljkeefe_0-1654636966753.png

When I put the variable (varP) in a label, it calculates the Date diff between Meeting B "Approved by" date and the Meeting A "Meeting Date" correctly. As soon here, it is 2 days. However, the varP in the Meeting Date date picker is showing 9 as you can see in the upper left-hand corner of the image. This is causing the IF statement to not work correctly. In this case, the Meeting Date for Meeting A should be the third Monday of July not the fourth.

iAm_ManCat
Most Valuable Professional
Most Valuable Professional

Len vs IsBlank? Experience 😞

I have been caught too many times where IsBlank is considered 'technically false' because of a partial or previous value still being looked at, whereas Len always calculates the current Length of the item at the current moment in time, which should be zero if it's truly blank.

 

For varP, I can't say for certain but I think the defaultDate is still looking at the previous value of varP, so we could try using the direct datediff comparison instead of the variable?

 

With({
        PrevFirstOfMonth: Date(Year(MeetingB.SelectedDate), Month(DateAdd(MeetingB.SelectedDate, -1, Months)), 1),
        WholeWeek: 7
    },
    With({
            DayOfWeekPrevFirstOfMonth: Weekday(PrevFirstOfMonth, StartOfWeek.Tuesday)
        },
        With({
                PrevFirstMonday: DateAdd(PrevFirstOfMonth, (1 * WholeWeek) - (DayOfWeekPrevFirstOfMonth))
            },
            With({
                    PrevThirdMonday: DateAdd(PrevFirstMonday, WholeWeek * 2),
                    PrevFourthMonday: DateAdd(PrevFirstMonday, WholeWeek * 3)
                },
                If( Len(MeetingB.SelectedDate)=0,
                    "", 
                    DateDiff( MeetingA.SelectedDate, MeetingB.SelectedDate,Days) <= 6, 
                    PrevThirdMonday,
                    PrevFourthMonday
                )
            )
        )
    )
)

 


@iAm_ManCat
My blog


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


@iAm_ManCat  Ah, yes, experience. Got it.

 

When I used DateDiff directly, I got a circular reference error. That's why I created the varP variable. If you know of a workaround for the circular reference error, then I might be in business. 

iAm_ManCat
Most Valuable Professional
Most Valuable Professional

Ok, so I think we might be able to get around this if we check for varP on the outer side of the formula and then do the calcs inside:

 

If( Len(MeetingB.SelectedDate)=0,
    "", 
    varP <= 6, 
    With({
            PrevFirstOfMonth: Date(Year(MeetingB.SelectedDate), Month(DateAdd(MeetingB.SelectedDate, -1, Months)), 1),
            WholeWeek: 7
        },
        With({
                DayOfWeekPrevFirstOfMonth: Weekday(PrevFirstOfMonth, StartOfWeek.Tuesday)
            },
            With({
                    PrevFirstMonday: DateAdd(PrevFirstOfMonth, (1 * WholeWeek) - (DayOfWeekPrevFirstOfMonth))
                },
                With({
                        PrevThirdMonday: DateAdd(PrevFirstMonday, WholeWeek * 2)
                    },
                        PrevThirdMonday
                    )
                )
            )
        )
        ,
        //Otherwise use the PrevFourthMonday
        With({
            PrevFirstOfMonth: Date(Year(MeetingB.SelectedDate), Month(DateAdd(MeetingB.SelectedDate, -1, Months)), 1),
            WholeWeek: 7
        },
        With({
                DayOfWeekPrevFirstOfMonth: Weekday(PrevFirstOfMonth, StartOfWeek.Tuesday)
            },
            With({
                    PrevFirstMonday: DateAdd(PrevFirstOfMonth, (1 * WholeWeek) - (DayOfWeekPrevFirstOfMonth))
                },
                With({
                        PrevFourthMonday: DateAdd(PrevFirstMonday, WholeWeek * 3)
                    },
                        PrevFourthMonday
                    )
                )
            )
        )
)

 

Could you give that a try and let me know if that's any better?

 

Oh and the other explanation about the IsBlank you had, you had it pointed directly at the control name 

IsBlank(MeetingB)

..And you would assume that it knows to look at the selectedDate property - but rarely that can fail where it can't determine which property it should be looking at as a default so you should also always explicitly define which property you are checking for IsBlank or looking at Len - the datepicker is the one I always use Len on as once the default date changes to an invalid state it can technically still have a date so the IsBlank says its not blank even though it has an error value, whereas Len of an error is also zero

IsBlank(MeetingB.SelectedDate)

IsBlank(MeetingB.X)

IsBlank(MeetingB.Height)

 


@iAm_ManCat
My blog


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


@iAm_ManCat 

I tried the above and varP is still calculating 9 when there is only 2 day difference between the two date pickers. I'm assuming this is why it's not applying the condition of the IF statement.

I have varP Set in the OnChange of the Meeting B date picker (which isn't one of the two date pickers involved but they are dependent on the date in this date picker). Not sure if that makes a difference.

 

 

I want to say thank you for hanging in here with me and helping.

iAm_ManCat
Most Valuable Professional
Most Valuable Professional

No worries! glad to help, one day hopefully you'll do the same for someone else 🙂

 

Ok, so we need to look at how varP is being generated.

I think this should be set on both OnChange of MeetingA and MeetingB

 

Because right now only a change to MeetingB will change varP right? so once its set then any change to MeetingA won't affect it, even though varP isreliant on MeetingA.

 

How is the DefaultDate for MeetingB derived?


@iAm_ManCat
My blog


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,379)