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
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,636)