Chris Potts
07/16/2025, 1:16 PMMauricio Cabezas
07/16/2025, 2:02 PMChris Potts
07/16/2025, 2:06 PMMauricio Cabezas
07/16/2025, 2:48 PMChris Potts
07/16/2025, 3:03 PMJoseph Heun
07/16/2025, 8:16 PMselect sum(DATETIME_DIFF(MIN({label/Hire_Start_Date.dayOfMonth}),MAX({label/Hire_Start_Date.day}) ))
using DATETIME_DIFF(MIN(date), MAX(date))
will only give you the difference between the earliest and latest dates in the data, which can undercount days if, for example, there's no data on the 1st of the month.
There are a few options to achieve your goal — calculating the full number of days in the selected period, like returning 31 for July even if data starts on July 2nd:
Option 1: Use a reference dataset with precomputed values
You can create a simple dataset that maps each month (or filter period) to the correct number of days. Then link that dataset in your model and create a metric like:
SELECT MAX({fact/days_in_month})
This ensures it always returns the correct number, regardless of whether there’s data on the first or last day.
Option 2: Dashboard plugin (advanced)
If you’re embedding the dashboard, a plugin can read the active date filter and dynamically calculate the difference between its start and end. This value can then be shown in a KPI or text widget. It’s more complex but allows full control.
Option 3: Multiple metrics to define the min and max dates first, and then use those in a separate metric to calculate the DATETIME_DIFF
.
Here’s how you could approach it:
Define the min and max date metrics:
-- Min Date in filter context
SELECT MIN({label/Hire_Start_Date.date})
-- Max Date in filter context
SELECT MAX({label/Hire_Start_Date.date})
Save these as separate metrics, for example:
Min Hire Date
and Max Hire Date
.
2. Use those metrics in a DATETIME_DIFF metric:
SELECT DATETIME_DIFF({metric/Min Hire Date}, {metric/Max Hire Date})
Just a heads-up though: this will
still return the difference based on data, not necessarily the full filter range — meaning it will only work correctly if there’s data present on both boundary dates.
If your goal is to calculate the difference based on the selected filter period, regardless of whether data exists on the 1st or last day, then one of the following alternatives is better:
• Use a reference table mapping periods to total days
• Use a dashboard plugin to extract the filter range dynamicallyChris Potts
07/17/2025, 9:06 AM