cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TerryR
Helper I
Helper I

Find Cycle Based on Date

I want to use powerapps to identify the cycle in which a product was produced.  I have a separate table set up like this...

 

Cycle      CycleStartDate

162         2019-05-29

161         2019-04-17

160         2019-02-27

159         2018-12-11

 

For example, if the product was produced on 3/16/2019, the app needs to show that the product was produced in cycle number 160.  Any ideas on how to do that?

 

 

24 REPLIES 24

@TerryR 

I would first put a label on your screen and set the text property to:

LookUp('[dbo].[CycleDates]',
       DateValue("7/22/2019") < CycleEndDate &&
       DateValue("7/22/2019") >= CycleStartDate
      ).Cycle_Number

Replace the hardcoded date with any value you know is valid. See if you get a value you expect or an error.

If you get an error, then I would remove your data source and then add it back in.  This all assumes that CycleEndDate and CycleStartDate are defined as Date fields in your table.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

It appears to me that the dates are not correlating between the one provided in the dte picker (or hardcoded in) and the date in the sql table.  When we set it up to look for the keyID = 21, for example, it pulls back the correct cycle, but not when we use date. Do the dates in the table and the target date need to be formatted the same?

When I put in DateValue("2019-05-29", "en-US") into the formula, the formula bar indicates that is equal to 5/29/2019m 12:00:00 AM.  The lookup table has dates formatted as 2019-05-29.

We finally got this working.  We had to change the date fields in the SQL lookup table to Char(10), then the formula below worked!

 

LookUp(CycleDataSource,(DateValue(CycleStartDate) <= DateValue2.SelectedDate) && DateValue(CycleEndDate) > DateValue2.SelectedDate, Cycle)

 

@TerryR 

Gald you got it working.  However, there is no need to set those columns to char columns...the date fields and the comparisons work perfectly well and take less "processing" (in the sense of conversion formulas) to deal with.

So, if you come across it again, I would lean toward the data column before going with a text column.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

That's what I would prefer too, if I could get it to work!  It's working this way though, so I'm not to excited about reinventing the wheel after working on if for a month last time.  Maybe next time!  Thanks for supporting me through the problem.  

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (2,431)