Author Topic: Row Wise and Column Wise total of Hour and Minutes  (Read 435 times)

vijay@spinetechnologies

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 87
    • View Profile
Row Wise and Column Wise total of Hour and Minutes
« on: April 24, 2023, 05:58:19 pm »
Hi Team,
How to achieve Row Wise and Column Wise Total of Hours and Minutes.
i.e if Minutes is greater than 59 then it should count as 1 hour and should be added in the hour part.

I have attached a ScreenShot for reference.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Row Wise and Column Wise total of Hour and Minutes
« Reply #1 on: April 25, 2023, 05:03:48 pm »
for row wise total, you can use column dependencies and for column wise total, summary can be used.

These 2 examples show both row and column wise calculations.

https://paramquery.com/pro/demos/summary

https://paramquery.com/pro/demos/summary_json

Following function can be used for addition of time values.

Code: [Select]
function addTime( times) {
  const totalMinutes = times.reduce((total, time) => {
    const [hours, minutes] = time.split(':').map(Number);
    return total + (hours * 60) + minutes;
  }, 0);

  const totalHours = Math.floor(totalMinutes / 60);
  const totalMinutesMod = totalMinutes % 60;

  const resultHours = String(totalHours % 24).padStart(2, '0');
  const resultMinutes = String(totalMinutesMod).padStart(2, '0');

  return resultHours + ":" + resultMinutes;
}

vijay@spinetechnologies

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 87
    • View Profile
Re: Row Wise and Column Wise total of Hour and Minutes
« Reply #2 on: April 26, 2023, 07:06:54 pm »
Hi Team,
Thanks for the Solution.

We have another case in which we are using Pivot Feature. In Pivot the Last Column is auto-generated, So in this scenario can we apply the above addTime function?

We have attached a screenshot for your reference.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Row Wise and Column Wise total of Hour and Minutes
« Reply #3 on: April 27, 2023, 02:35:25 pm »
Yes, of course. make the necessary changes in function since in your case "." is the separator instead of ":" between hour and minute.