I am developing a repeating table in PowerApps that contains a list of tasks (see image).
These tasks have a start date, number of days, and an end date. Creating the task table was not difficult, but, I have a requirement to move tasks up and down and I can't do that. because I need to recalculate date again in the new order given
Solved! Go to Solution.
That should have been your first post - it has taken 20 to get there. You have to help us help you.
You also need to understand your own code
SortByColumns(
CollectionTask,
"TaskOrder"
)
is doing exactly what you have asked it to do - sort by Task Order, so when the task order changes, so do the items. If you want the gallery sorted by a date (as I described) , then sort by the date column
SortByColumns(
CollectionTask,
"Start Date"
)
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.
This is the solution
Button Up
UpdateContext({varChangeItemONESortNumber: ThisItem.TaskOrder});
UpdateContext({varChangeItemTWOSortNumber: ThisItem.TaskOrder - 1});
Patch(
CollectionTask,
ThisItem,
{TaskOrder: varChangeItemTWOSortNumber}
);
Patch(
CollectionTask,
First(
Filter(
CollectionTask,
TaskOrder = varChangeItemTWOSortNumber
)
),
{TaskOrder: varChangeItemONESortNumber}
)
Button Down
UpdateContext({varChangeItemONESortNumber: ThisItem.TaskOrder});
UpdateContext({varChangeItemTWOSortNumber: ThisItem.TaskOrder + 1});
Patch(
CollectionTask,
ThisItem,
{TaskOrder: varChangeItemTWOSortNumber}
);
Patch(
CollectionTask,
First(
Filter(
CollectionTask,
TaskOrder = varChangeItemTWOSortNumber
)
),
{TaskOrder: varChangeItemONESortNumber}
)
on the item property in the gallery
SortByColumns(CollectionTask,"TaskOrder")
Hi @Ramonjairo31 ,
You can sort a gallery in date order - what do you mean by "recalculate"?
Hi @Ramonjairo31 ,
Could you please share more details about your last sentence, 'recalculate date again '?
You can not adjust the row order arbitrarily, the gallery can only be sorted on columns in Ascending or Descending order.
If you want to move some tasks up or down, the only way is to modify the index column to meet the sort order requirement.
Hope this helps.
Sik
The task works like this “recalculate”
I’m have a overall start date, input that into the start date of the first line and then add the number of days to get the end date and then use this end date as the start date for the next line and so on, this is working fine but now I need to move task up and down and do this math on the new orden given
Can you please share the code you are using to "recalculate", in particular how are you identifying what is the "next row"
Thanks @Ramonjairo31 ,
I looked at your code and getting my mind around it (sort of) come up with this
With(
{
vAdd:
Mod(
Value(TextInputCount_1.Text),
5
),
vBase:
Value(TextInputCount_1.Text) +
RoundDown(
Value(TextInputCount_1.Text) / 5,
0
) * 2,
vDay:
Weekday(DatePickerStartDate_1.SelectedDate)
},
Set(
VarCountDate,
DateAdd(
DatePickerStartDate_1.SelectedDate,
vBase +
If(
vAdd>(5-vDay),
vAdd,
0
)
)
)
)
So now you come up with varDateCount, how do you use it to create a new record?
Thank you very much @WarrenBelz
Basically, I'm using this in the save button for a new lines
then new lines come up with the last day
as attachment, I put a copy of the app I have so far using your code but now will be great to move a task up and down a recalculate
The code I gave was just a much shorter way of achieving the same results - I hope it had helped you understand a bit more about other options.
I cannot open the app (I am getting "cannot open in this version" error), however in the below code
If(
VarEditPressed,
false,
Collect(
CollectionTask,
{
TaskOrder: Value(Last(CollectionTask).TaskOrder + 1),
TaskLine: "",
Status: "",
StartDate: Text(VarCountDate),
Days: "",
EndDate: "",
AssignedTo: "",
ChargeAccount: "",
ShowButtons: true
}
)
)
why are you using StartDate: Text(VarCountDate), into a Date field? Also if the Items of the gallery are sorted by date, they should automatically adjust when the new item is added . What is the Items property of this gallery?
thanks Mr @WarrenBelz you code was really useful also taught me about the function "WITH" I will use it in my apps.
I'm using text under StartDate because that field inside the collection is text type, however, when I patch all this into SharePoint I do the conversion into date no problem so far with it, but I'm an open book
Let's supposed that a user created a few tasks and saved all of them into the database so far everything is fine but then he's back to the system and decided to move the Task that was in order number 1 to be in order number 3 and the task that was on order number 3 to be on order number 1, now the problem comes
It´s the following: Task should be organized in this way again: overall start date, input that into the start date of the first line and then add the number of days to get the end date and then use this end date as the start date for the next line and so on,
so basically, I'm doing this math when the user is adding a new task in the system "on Button Save task Line"
So if the user changes the order on any tasks the math that was made before, won't work anymore.
I want to create a button outside the gallery which is able to do this math not matter the order given
User | Count |
---|---|
167 | |
90 | |
73 | |
66 | |
57 |
User | Count |
---|---|
213 | |
153 | |
97 | |
88 | |
67 |