I have a table of songs and their durations. How can i display this as MM:SS and then summarize those durations to show as a summary of how long a “playlist” is.
I’ve done this before but don’t remember the exact formulas. So I am cheating a bit here by letting ChatGPT answer (with some edits…)
———
In Grist, you can use column-wide Python formulas to compute on your data. If you have durations in MM:SS format in Grist and want to sum them, here’s a method leveraging Grist’s Python capabilities:
-
Convert MM:SS to Seconds:
- Suppose your durations are in a column named
Duration
. - Create a new column, say
Seconds
. Set its formula to:minutes, seconds = map(int, $Duration.split(":")) return minutes * 60 + seconds
- Suppose your durations are in a column named
-
Sum the Seconds:
- Add a summary table to get the sum of
Seconds
column (total, or grouped by something).
- Add a summary table to get the sum of
-
Convert the Sum Back to MM:SS Format:
- Create another column, say
TotalDuration
, at the position where you want to display the total duration in MM:SS. - Set its formula (for the cell where you want the total) to:
total_seconds = $Seconds return f"{total_seconds // 60}:{total_seconds % 60:02}"
- Create another column, say
Awesome thanks so much, after using that i was able to use AI to get my total per playlist. very cool.
Thanks.