web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / If statement in text p...
Power Apps
Answered

If statement in text property of a label

(0) ShareShare
ReportReport
Posted on by 224

Hello,

 

I have a gallery that has a label that shows a start date and end date. I want the text to show only the start date if it's a single day event, and if it's a multiple day event, then show the date range.

 

I have the below code in the text property which is showing the true value correctly, but the else value doesn't populate. Is this a restriction with the label or am I missing something else?

 

If(ThisItem.'Vacation Start Date' = ThisItem.'Vacation End Date', ThisItem.'Vacation Start Date', ThisItem.'Vacation Start Date' & " - " & ThisItem.'Vacation End Date')

 

Categories:
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @as733y 

    Try 

    If(
     DateDiff(
     ThisItem.'Vacation Start Date', 
     ThisItem.'Vacation End Date')=0, 
     ThisItem.'Vacation Start Date',
     ThisItem.'Vacation Start Date' & " - " & ThisItem.'Vacation End Date'
     )
  • as733y Profile Picture
    224 on at

    @Drrickryp 

     

    It doesn't seem to work. 

     

    Same issue. The single day works (true value) , but the date range doesn't show (else value).

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @as733y 

    It works perfectly for me. There is some problem with how you are saving your dates. Try using datepickers with DisplayMode set to View.

  • timl Profile Picture
    37,287 Super User 2026 Season 2 on at

    @as733y 

    To try to diagnose this, if you set the formula to show the hardcoded text "else", does this text appear in the gallery?

    The purpose of this is to verify that the If function can parse a simple expression in the else branch in the call to 'if'.

    If(ThisItem.'Vacation Start Date' = ThisItem.'Vacation End Date', 
     ThisItem.'Vacation Start Date', 
     "else"
    )

     

  • as733y Profile Picture
    224 on at

    @timl no, the "else" doesn't appear.

     

    It seems that the else portion fails if I have anything within "" and/or if I have a &. I can get the below to work, but like I mentioned, if I try to just show the start and the end date, then the else fails.

     

    FYI, this is a subtitle label in a gallery, if that makes a difference.

     

    If(ThisItem.'Vacation Start Date' = ThisItem.'Vacation End Date', 
     ThisItem.'Vacation Start Date', ThisItem.'Vacation End Date')

     

  • Verified answer
    timl Profile Picture
    37,287 Super User 2026 Season 2 on at

    Hi @as733y 

    I think if you convert the true value to text, that should hopefully make the false value appear:

    If(ThisItem.'Vacation Start Date' = ThisItem.'Vacation End Date', 
     Text(ThisItem.'Vacation Start Date', ShortDate), 
     ThisItem.'Vacation Start Date' & " - " & ThisItem.'Vacation End Date'
    )

     

  • Verified answer
    as733y Profile Picture
    224 on at

    @Drrick 

     

    You're comment about the formatting got me to the solution! Below works!

     

    If(
     Text(
     ThisItem.'Vacation Start Date',
     ShortDate
     ) = Text(
     ThisItem.'Vacation End Date',
     ShortDate
     ),
     Text(
     ThisItem.'Vacation Start Date',
     ShortDate
     ),
     (Text(
     ThisItem.'Vacation Start Date',
     ShortDate
     ) & " - " & Text(
     ThisItem.'Vacation End Date',
     ShortDate
     ))
    )

     

     

     

  • as733y Profile Picture
    224 on at

    It works! Thank you @timl !!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard