This expression checks by calculating how many weeks there are in this range if the last day is forwarded by one day? For example, if the last day is a Friday, then it moves to Saturday, and that partial week doesn't count towards our total because DATEDIFF('week'. Since there can never be fewer Saturdays than Sundays in a given range (because Sunday is after Saturday), we will check whether the last day in the range is a Saturday. The following example is for Snowflake, and will need to be updated as necessary for your specific SQL dialect. You will also want to make sure you have the date timeframe declared in the dimension_groups that will represent your start date and end date. Note:You will want to make sure your database will return a day of week index of 0 for Sunday and 6 for Saturday this is important, or the calculations will be one or two days off. But, there is a more straightforward way, using a single short query, which you can define in the sql parameter of a dimension or measure in LookML. One way of achieving this is to create a derived table with the necessary logic. What if you want to exclude weekend days (Saturday and Sunday)? However, the functions above will count all the days between the two specified dates. Snowflake: DATEDIFF('day', start, stop) AS days Postgres: DATEPART('day', start - stop) AS days Redshift: DATEDIFF('day', start, stop) AS days If you'd like to count the days between two dates, you could use the SQL DATEDIFF function, which simply counts the days between two points in time: Looker will not be updating this content, nor guarantees that everything is up-to-date.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |