This tutorial will teach you how to calculate the remaining days in a month, the total days, and the days that have already passed. By learning these techniques, you can effectively track and visualize important time-related metrics, improving your data analysis abilities in Looker Studio.
You can follow this step-by-step guide or watch our YouTube video for a more visual walkthrough.
Table of contents
Step-by-step guide with examples
Step 1: Set up your scorecard
Step 2: Calculate the number of days in the month
To calculate the number of days in a selected month using looker studio, you will need to create a calculated field and use the following formula:
The formula provided for calculating the number of days in a month in looker studio is designed to work with a date range specified by the created_date
field. This field represents a range of dates that may span across two different months. The formula calculates the number of days in the month with the most days within this date range. Let’s break it down step by step for better understanding:
Number of days in month
MAX(DATE_DIFF(
DATE(
YEAR(created_date) + IF(MONTH(created_date) = 12, 1, 0),
IF(MONTH(created_date) = 12, 1, MONTH(created_date) + 1), 1
),
DATE(YEAR(created_date), MONTH(created_date), 1)
))
DATE(YEAR(created_date), MONTH(created_date), 1)
This part of the formula creates a date representing the first day of the month for the earliest date in the created_date
range.
IF(MONTH(created_date) = 12, 1, MONTH(created_date) + 1), 1
created_date
range. If the range ends in december, it rolls over to january of the next year.
DATE_DIFF(...)
The DATE_DIFF
function calculates the difference in days between the two dates created in the previous steps.
MAX(...)
MAX
function is used to ensure that the formula returns the number of days in the month with the most days within the created_date
range. This is particularly important when the range spans across two different months. created_date
. It does this by determining the first day of the month for the earliest date and the first day of To calculate the number of days in a selected month using looker studio, you will need to create a calculated field and use the following formula:
Step 3: Calculate elapsed days in the month
The final step is to determine how many days are left in the month. This is done by subtracting the elapsed days from the total days in the month. So, if there are 30 days in november and 5 days have elapsed, you have 25 days remaining. To do so, you’ll need to create 3 calculated fields.
MAX(created_date)
DATETIME_TRUNC(Last Date of Range, MONTH)
DATETIME_DIFF(Last date of range, start of month of last date range, DAY) + 1
Step 4: Calculate the remaining days in the month
Number of days in month - elapsed days in month
Conclusion
In future tutorials, we will learn how to use this scorecard in a monthly goal tracker, which will help you set and monitor targets based on the number of days that have passed and the number of days remaining in the month.