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 / Struggling with Lookup...
Power Apps
Answered

Struggling with Lookup against date fields in Sharepoint

(0) ShareShare
ReportReport
Posted on by 195

Hi all

 

Hitting my head against a brick wall with this and I don't understand why.... it seems like it should be really simple...

 

I'm trying to set a variable for a Payroll Month name (which will come out like "December 2023" for example) by looking up today's date vs start and end dates in a sharepoint list. The code to set the variable is:

 

 

Set(TSCurrMonth,LookUp(HRPayrollMonths,StartDate<=Today() && EndDate>=Today()).Title)

 

 

The payroll months don't line up with the calendar months which is why I can't just use normal date functions. There is an item in the "HRPayrollMonths" list that would qualify for today:

crispybits1977_0-1702641236698.png

 

However there are no red error bars and the variable comes out as empty. What am I missing?

Categories:
I have the same question (0)
  • Verified answer
    Sickle-Cell Profile Picture
    600 Super User 2024 Season 1 on at

    Hi @crispybits1977,

     

    Try this instead.

     

    Set(TSCurrMonth,LookUp(HRPayrollMonths,StartDate<=Today() && EndDate>=Today(),Title))
  • crispybits1977 Profile Picture
    195 on at

    Still nothing I'm afraid - it's returning text just the text is blank... (I did have it returning table or record for some of my other tries at different variations on the theme...)

  • Sickle-Cell Profile Picture
    600 Super User 2024 Season 1 on at

    Hi @crispybits1977,

     

    I'm not seeing any obvious reasons for the error, would you mind doing a few things to help me narrow this down?

    Can you highlight part of the Loopkup code until you get the option to view the information it's collecting and see if that's blank? If that doesn't work (it can be fiddly in my experience) could you create a new text label and set the text code to 

    LookUp(HRPayrollMonths,StartDate<=Today() && EndDate>=Today(),Title)

    and confirm what it displays? 

  • crispybits1977 Profile Picture
    195 on at

    OK so this is just getting weird.

     

    If I set the variable and have the variable display in a text label, it's blank with data type text.

     

    If I set the label directly with the formula it displays correctly.

     

    crispybits1977_0-1702643990758.png

     

    crispybits1977_1-1702644046717.png

     

     

  • Sickle-Cell Profile Picture
    600 Super User 2024 Season 1 on at

    Hi @crispybits1977,

     

    Yeah, that's very odd. Let's try changing the syntax and see if that sorts it. Try the below.

     

    Set(
     TSCurrMonth,
     LookUp(
     HRPayrollMonths,
     And(
     StartDate<=Today(),
     EndDate>=Today()
     ), 
     Title
     )
    )
  • crispybits1977 Profile Picture
    195 on at

    A bit more info - I noticed the "format text" option was greyed out signalling an error somewhere in the code (this is all running in my "OnStart" code) so I cut the two lines out and pasted them back in - suddenly I have red lines and intellisense text on the error...

    crispybits1977_2-1702644533785.png

     

  • Verified answer
    Sickle-Cell Profile Picture
    600 Super User 2024 Season 1 on at

    Hi @crispybits1977,

     

    Okay, one issue I've had in the past which may be related to this. Sharepoint has a habit of renaming fields. If you try to rewrite the Lookup function, does it auto-complete StartDate as a field? If not, try looking for fields called field_1 or field_2, that kind of thing, as Sharepoint may not be pulling through the correct name.

  • crispybits1977 Profile Picture
    195 on at

    Same thing is happening with the latest batch of new code btw - only the text box with the variable in is now throwing an explicit error of 'expects data type "text", being given "error"'

  • crispybits1977 Profile Picture
    195 on at

    It's not even popping up the StartDate field in the auto-complete options when I clear it to retype

  • crispybits1977 Profile Picture
    195 on at

    Retyped it all from scratch and it gave me the autocompletes, but I'm back to where I started now with the variable displaying blank text.

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 324 Most Valuable Professional

#2
11manish Profile Picture

11manish 193

#3
Valantis Profile Picture

Valantis 138

Last 30 days Overall leaderboard