I have this power app that has a start and stop date and time
I need to be able to have the work duration field calculate the amount based on which button is checked in the Duration Type
So if it is hours how many hours between Start/Stop or for days how many days.
Is this possible?
Solved! Go to Solution.
You don't really need to use context variables, although it does make the code easier to read. But as I said you do need to create a full date and time value to use in datediff. But this shoudl work without using the onChange event and context variables.
IF(Radio1.SelectedText.Value = "Hours",DateDiff(
DateTimeValue(
Text(
StartDatePicker.SelectedDate,"[$-en-GB]yyyy.mm.dd ")&
StartHourDropdown.Selected.Value&
":"&
StartMinuteDropdown.Selected.Value
)),
DateTimeValue(
Text(
EndDatePicker.SelectedDate,"[$-en-GB]yyyy.mm.dd ")&
EndHourDropdown.Selected.Value&
":"&
EndMinuteDropdown.Selected.Value
)),
Hours),DateDiff(
DateTimeValue(
Text(
StartDatePicker.SelectedDate,"[$-en-GB]yyyy.mm.dd ")&
StartHourDropdown.Selected.Value&
":"&
StartMinuteDropdown.Selected.Value
)),
DateTimeValue(
Text(
EndDatePicker.SelectedDate,"[$-en-GB]yyyy.mm.dd ")&
EndHourDropdown.Selected.Value&
":"&
EndMinuteDropdown.Selected.Value
)),
Days))
This is with the correct names, however it doesnt like the part in red in the forumla
UpdateContext({
chosenStartTime:
DateTimeValue(
Text(
DateValue1.SelectedDate,"[$-en-US]yyyy.mm.dd ")&
HourValue1.Selected.Value&
":"&
MinuteValue1.Selected.Value
)
)}
);
UpdateContext({
chosenEndTime:
DateTimeValue(
Text(
DateValue2.SelectedDate,"[$-en-US]yyyy.mm.dd ")&
HourValue2.Selected.Value&
":"&
MinuteValue2.Selected.Value
)
)}
)
I took off the extra ) and it works perfect!! Thank you
UpdateContext({
chosenStartTime:
DateTimeValue(
Text(
DateValue1.SelectedDate,"[$-en-US]yyyy.mm.dd ")&
HourValue1.Selected.Value&
":"&
MinuteValue1.Selected.Value
)
}
);
UpdateContext({
chosenEndTime:
DateTimeValue(
Text(
DateValue2.SelectedDate,"[$-en-US]yyyy.mm.dd ")&
HourValue2.Selected.Value&
":"&
MinuteValue2.Selected.Value
)
}
)
You will have issues with the solution you are trying.
This is quite simple to achieve without the OnChange actions (which will not occur on a form edit - and thus your variable will be empty).
Your Default formula on the WorkDuration datacardvalue control should be the following:
DateDiff(
DateTimeValue(
Text(DateValue1.SelectedDate, ShortDate) & " " &
HourValue.Selected.Value & ":" & MinuteValue1.Selected.Value & ":00"
),
DateTimeValue(
Text(DateValue2.SelectedDate, ShortDate) & " " &
HourValue2.Selected.Value & ":" & MinuteValue2.Selected.Value & ":00"
),
Hours
) / If(Radio3.Selected.Value="Hours", 1, 24)
- Get rid of the OnChange actions on the controls.
- Avoid using .SelectedText on dropdowns as it is a Deprecated property.
- Make sure that you have not changed the Default properties of the datepickers or hour or minute controls. They should be based on the Parent.Default value.
EDIT: There was an extra paren in the original formula. It is corrected above.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
User | Count |
---|---|
199 | |
70 | |
50 | |
46 | |
20 |
User | Count |
---|---|
253 | |
120 | |
84 | |
79 | |
68 |