I’m trying to take a date field 2021-03-01 (as an example) and turn it into a custom dimension that would be 2021-03 (as an example).
I can use and extract function and concat to pull the year and month and connect them but the output is a string, not a number, 2021-3. If I’m pulling a series, it won’t sort correctly.
Any suggestion on how to change the YYYY-mm-dd format to a YYYY-mm format as a custom dimension?
Solved! Go to Solution.
Hi Cory,
As Dawid mentioned, it is best to do this in LookML as custom dimensions are not version controlled and the custom dimension you create will run slower as the calculation is more complicated.
If it’s not possible to get the month timeframe added to the date dimension group in LookML, there is a workaround:
concat(
extract_years(${view.date})
,"-"
,
if(extract_months(${view.date})<10
, concat("0",extract_months(${view.date}))
,concat("",extract_months(${view.date}))
)
)
It adds a ‘0’ to the month where the month number is less than 10 to give YYYY-mm format.
Hope this helps,
Naomi