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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Issue in Power App dat...
Power Apps
Answered

Issue in Power App date range selection with other values

(0) ShareShare
ReportReport
Posted on by 11

Hi ,

 Can you help me in this . I do have a form like below which will take multiple values from each drop down with selected date range and mark the data in separate rows .

Issue : If I select a data range example as below from June 1 to 6 ,data's are getting added from 2 to 6 June .From date is getting missed - June 1.

 

Thanks !

 

Set(

 

 fromDate,

 

 DatePicker1.SelectedDate

 

);

 

 

Set(

 

 toDate,

 

 DatePicker2_1.SelectedDate

 

);

 

 

Clear(MyCollection1);

 

ForAll(

 

 Sequence(DateDiff(fromDate, toDate)) As seq,

 

 Collect(MyCollection1,

 

 AddColumns( 'ComboBox1_4 name'.SelectedItems As C , Date , DateAdd(fromDate, seq.Value, TimeUnit.Days), Name,'ComboBox1_4 name'.SelectedItems)

 

 )

 

 );

 

 // Check if a record with the same Name and Date already exists
Set(
 existingRecords,
 Filter(
 Table1,
 Name = 'ComboBox1_4 name'.Selected.Value &&
 Date = DatePicker1.SelectedDate
 )
);

 

 

 

If(
 CountRows(existingRecords) > 0,
 // Get the name of the existing record
 Set(
 existingRecordName,
 First(existingRecords).Name
 );
 Notify("A record with the same Name and Date already exists for " & existingRecordName, NotificationType.Error),
 // If no existing record found, add a new record
 ForAll(
 MyCollection1 As C,
 Patch(
 Table1,
 Defaults(Table1),
 {
 Manager: 'Dropdown1_4 -mng'.Selected.Value,
 Team: 'Dropdown2_4- team'.Selected.Value,
 Name: C.Value,
 Date: C.Date,
 Hours: TextInput1.Text,
 Leave: 'Dropdown4-leave'.Selected.Value
 }
 )
 );
 Navigate(DataTable1)
)

 

NishaN323_0-1717780830164.png

 

Categories:
I have the same question (0)
  • Verified answer
    madlad Profile Picture
    2,637 Moderator on at

    Hi!

     

    It looks like this is occurring for 2 reasons:

    1. DateDiff is returning 1 less than you want(i.e you want a value of 6 for June 1 - 6, it returns 5)

    2. Since you are starting with DateAdd(fromDate, seq.Value), you are starting with "fromDate + 1"

     

    This can be easily fixed by subtracting one from "fromDate" when it is defined. Try something like the following:

     

    Set(
     fromDate,
     DatePicker1.SelectedDate - 1
    );
    

     

     

    Hope this helps!

  • Verified answer
    WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    @NishaN323 ,

    @madlad is on the right track, but you need to add on a day in the sequence then subtract one from the sequence value so you get the first day included. Also you do not need those two "one use" Variables hanging around adding to the app load.

    Clear(MyCollection1);
    ForAll(
     Sequence(
     DateDiff(
     DatePicker1.SelectedDate, 
     DatePicker2_1.SelectedDate
     ) + 1
     ) As seq,
     Collect(
     MyCollection1,
     AddColumns( 
     'ComboBox1_4 name'.SelectedItems, 
     Date, 
     DateAdd(
     DatePicker1.SelectedDate, 
     seq.Value - 1, 
     TimeUnit.Days
     ),
     Name,
     'ComboBox1_4 name'.SelectedItems
     )
     )
    );

    I have not looked at the rest of your logic and assume it works.

     

  • NishaN323 Profile Picture
    11 on at

    @madlad @WarrenBelz ,Thank you so much both of your thoughts worked . But I do have one more issue in my above code if I choose different date in To date selection its taking today as default and keep adding date values till today instead of mentioned to date .

     

    Example : June 1 to June 7 means its inserting values till 10(todays) instead till June 7 which I mentioned as date range.

     

    Looking for your help here.

     

    Thanks !!

  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    @NishaN323 ,

    I am not sure what you mean - the code should create records for all dates (inclusive) between the two dates chosen in the date pickers

  • NishaN323 Profile Picture
    11 on at

    @WarrenBelz , Thanks for the reply ,Example : If I choose a date range from June 1 to 5 ,Records are getting inserted from June 1 to 10 instead of To value (June 5) .To date is by default taking today irrespective of To date selection.

    Set(
    
     
    
     fromDate,
    
     
    
     DatePicker1.SelectedDate -1
    
     
    
    );
    
     
    
     
    
    Set(
    
     
    
     toDate,
    
     
    
     DatePicker2_1.SelectedDate 
    
     
    
    );
    
     
    
     
    
    Clear(MyCollection1);
    
     
    
    ForAll(
    
     
    
     Sequence(DateDiff(fromDate, toDate)) As seq,
    
     
    
     Collect(MyCollection1,
    
     
    
     AddColumns( 'ComboBox1_4 name'.SelectedItems As C , Date , DateAdd(fromDate, seq.Value , TimeUnit.Days), Name,'ComboBox1_4 name'.SelectedItems)
    
     
    
     )
    
     
    
     );
    
     
    
     // Check if a record with the same Name and Date already exists
    Set(
     existingRecords,
     Filter(
     Table1,
     Name = 'ComboBox1_4 name'.Selected.Value &&
     Date = DatePicker1.SelectedDate
     )
    );
    
     
    
     
    
     
    
    If(
     CountRows(existingRecords) > 0,
     // Get the name of the existing record
     Set(
     existingRecordName,
     First(existingRecords).Name
     );
     Notify("A record with the same Name and Date already exists for " & existingRecordName, NotificationType.Error),
     // If no existing record found, add a new record
     ForAll(
     MyCollection1 As C,
     Patch(
     Table1,
     Defaults(Table1),
     {
     Manager: 'Dropdown1_4 -mng'.Selected.Value,
     Team: 'Dropdown2_4- team'.Selected.Value,
     Name: C.Value,
     Date: C.Date,
     Hours: TextInput1.Text,
     Leave: 'Dropdown4-leave'.Selected.Value
     }
     )
     );
     Navigate(DataTable1)
    )

     

  • WarrenBelz Profile Picture
    153,084 Most Valuable Professional on at

    @NishaN323 ,

    I am not sure what you are trying to achieve here as that code will create a record with a Date and Value field for each combination of the Date and the selected items in the combo box, plus a Table field Name in each record with all the selected items again. However there is nothing in there that refers to the current day. If the DefaultDate of one of the Date Pickers is Today(), it is possible it is resetting before the code is run.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard