Likely something you’d have to put into LookML, especially if you’re also trying to incorporate holidays. There are other discussions around this, like:
WITH data AS (
SELECT
'2023-01-13'::DATE AS start_d,
LEAST(DATE_PART(DAYOFWEEKISO, start_d), 5) AS start_dow,
'2023-02-24'::DATE AS end_d,
LEAST(DATE_PART(DAYOFWEEKISO, end_d), 5) AS end_dow,
end_d - start_d AS diff,
end_dow - start_dow AS dow_diff,
FLOOR(diff / 7) AS weeks_diff,
ABS(end_dow - start_dow) AS dow_diff_abs
)
SELECT
IFF(weeks_diff >= 1, (weeks_diff * 5) + dow_diff_abs - IFF(dow_diff < 0, 1, 0), dow_diff_abs) AS bd
FROM data;
I had the same issue converting from calendar to business days in Looker. I was pulling data from Google Tables, so I did not want to solve the issue in the database but wanted to in the report. The solution I came up with does not take holidays into account, so it may not be the right fix for everyone, but it was sufficient for my reporting requirements.
I created a calculated field with the date_diff formula:
DATE_DIFF(End Date, Start Date)
Then I created a second calculated field that I would actually use in my report that is a very simple solution by dividing by 7 and multiplying by 5 any of the Date_Diff calculations that are above 5:
I included the rounding formula, since formatting is limited within the column field. This was a simple but not completely accurate solution, but I thought I would share my work around.
Basically, for each 7 days consider only 5. Then add the rest and substract 2 days if the start date is before the end date (meaning start on Monday, end on Thursday).
Considering adding special logic if the start or end date can be on a weekend.