Goran Jakimovski
05/17/2024, 7:38 AMMoises Morales
05/17/2024, 9:55 AMGoran Jakimovski
05/17/2024, 10:02 AMJakub Sterba
05/17/2024, 10:52 AMselect count({label/date.day},{dataset/order_lines})
Other approach can be to use MIN/MAX in combination with DATETIME_DIFF if there exists record with date at the beginning and end of selected date range:
select datetime_diff(min({label/date.day},{dataset/order_lines}),max({label/date.day},{dataset/order_lines}))+1
In case the fact table contains sparse data you may want to add date dimension dataset to your model with one record for each day which would be used for counting of days. Such dataset can be in many databases created as SQL dataset. For example following query generates records for last 365 days in Snowflake:
select
dateadd(
day,
'-' || row_number() over (order by null),
dateadd(day, '+1', current_date())
) as date
from table (generator(rowcount => 365))
The query depends on SQL dialect of your database. You may use GENERATE_SERIES function for MS SQL or PostgreSQL for example.