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

Removing the (-) from the calculated result

Hello,

I have a Sharepoint list that I am customizing it using Power Apps form.

In this list, I have a column and is a Date and Time, and I have a label that calculates the differences between two dates/time values.

What I want to achieve is the following:

The result of the Total Days returns a negative number (Since the today's date is later than the date the user selected), I would like to remove (-) operator from the calculated result and append "Day" if the DateDiff result was equal to 1 and "Days" if it was greater than 1.

The function that returns the negative result:

 

"Total Days: " & If(DateDiff(DatePicker1.SelectedDate,DataCardValue7.SelectedDate, Days)=1, DateDiff(DatePicker1.SelectedDate,DataCardValue7.SelectedDate) & " Day", DateDiff(DatePicker1.SelectedDate,DataCardValue7.SelectedDate) & " Days")

 

 

Please have a look at the screenshot below:

Capture.JPG

What should be the updated function to remove the (-) operator from the results?

Can please someone explains in detail and provide an example?

Any help will be greatly appreciated.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Julien2 ,

I tested this the wrong way around - please look at the below and you probably will understand the small issue. Have a look at the Abs function as it is very useful. Also the With function - it does nothing more than set what is essentially a Context Variable that only runs for the code and saves re-typing the same thing.

"Total Days: " & 
With(
   {
      vDays:
      DateDiff(
         DatePicker1.SelectedDate,
         DataCardValue7.SelectedDate, 
         Days
      )
   },
   Abs(vDays) & 
   If(
      Abs(vDays)=1,
      " Day",
      " Days"
   )
)

absDays.png

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

3 REPLIES 3
WarrenBelz
Super User
Super User

Hi @Julien2 ,

Try this

"Total Days: " & 
With(
   {
      vDays:
      DateDiff(
         DatePicker1.SelectedDate,
         DataCardValue7.SelectedDate, 
         Days
      )
   },
   Abs(vDays) & 
   If(
      vDays=1,
      " Day",
      " Days"
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @WarrenBelz ,

Thank you for providing an example. I have used the formula you mentioned but unfortunately, if the result was equal to 1 it shows "1 Days" knowing that it should show "1 Day" instead.

Please have a look at the screenshot below:

Capture.JPG

Looking forward to your response.

Thank you!

Hi @Julien2 ,

I tested this the wrong way around - please look at the below and you probably will understand the small issue. Have a look at the Abs function as it is very useful. Also the With function - it does nothing more than set what is essentially a Context Variable that only runs for the code and saves re-typing the same thing.

"Total Days: " & 
With(
   {
      vDays:
      DateDiff(
         DatePicker1.SelectedDate,
         DataCardValue7.SelectedDate, 
         Days
      )
   },
   Abs(vDays) & 
   If(
      Abs(vDays)=1,
      " Day",
      " Days"
   )
)

absDays.png

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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