cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Strange Bug in Gallery when using DateDiff() in If statement

I have noticed this strange behavior.

What I am trying to do:

If DateFrom and DateTo is the same date show only one date if they are different show two dates with – in between them.

 

My setup:

 1.png

Formula of 1.:

2.png

If(
    DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days) = 0,
    ThisItem.DateFrom,
    ThisItem.DateFrom&" - "&ThisItem.DateTo
)



 

To test I put some extra fields

Formulas

2.

DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days)

3.

"DateFrom: "&ThisItem.DateFrom

4.

"DateTo: "&ThisItem.DateTo

5.

ThisItem.DateFrom&" - "&ThisItem.DateTo

 

Database structure (showing only fields in question):

CREATE TABLE VacationRequest (
    DateFrom date NOT NULL,
    DateTo date NOT NULL,
);

 

 

This is clearly a bug or am I missing something? I can reproduce this 100% of the time.

  1. Have a database with two date fields
  2. Create a gallery
  3. In text field write the following formula:
If(
    DateDiff(ThisItem.Date1,ThisItem.Date2,Days) = 0,
    ThisItem.Date1,
    ThisItem.Date1&" - "&ThisItem.Date2
)

 

I have also tested this with different table where dates were datetime variable and got same results.

 

Crazily enough if you play with formula and reverse it, it works:

3.png

If(
    DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days) <> 0,
    ThisItem.DateFrom&" - "&ThisItem.DateTo,
    ThisItem.DateFrom     
)

 

 

 

Or if you add an empty string:

 

4.png

If(
    DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days) = 0,
    ThisItem.DateFrom&"",
    ThisItem.DateFrom&" - "&ThisItem.DateTo   
)
1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Strange Bug in Gallery when using DateDiff() in If statement

Thank you for reporting this issue!

 

The issue is that there are two different types of data in the true_value and else_value for the If function: a Date value and a string. If you convert the date to a string, then this scenario should work:

If(
    DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days) = 0,
    Text(ThisItem.DateFrom),
    ThisItem.DateFrom & " - " & ThisItem.DateTo
)

So you can use this workaround for now, while the fix doesn't get released.

View solution in original post

1 REPLY 1
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Strange Bug in Gallery when using DateDiff() in If statement

Thank you for reporting this issue!

 

The issue is that there are two different types of data in the true_value and else_value for the If function: a Date value and a string. If you convert the date to a string, then this scenario should work:

If(
    DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days) = 0,
    Text(ThisItem.DateFrom),
    ThisItem.DateFrom & " - " & ThisItem.DateTo
)

So you can use this workaround for now, while the fix doesn't get released.

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (4,466)