I am quite new to using Looker Studio.
I have always worked on Power BI in the past, however, in the new company, Looker Studio is now being introduced (coming from Qlik).
The difficulty I’m encountering is recreating a field based on the date field for PY (Previous Year):
Calculated simply as “current date - 364 days.”
Below an example of what i want to achieve.
you can have a look at https://www.googlecloudcommunity.com/gc/Technical-Tips-Tricks/Methods-for-Period-Over-Period-PoP-Analysis-in-Looker/ta-p/587538, it contains well explained guides to use PoP methods. In your example, you could have a look at method 3 Current Period and Previous Period.
It offers you the option of parametrising the period you want to compare your data with, but for your example, you can use the concept that i mention below, where you create a measure that returns ‘this’ or ‘last’ depending on your conditions, then you filter your measure using it:
## ---------------------- TO CREATE FILTERED MEASURES ---------------------------- ##
dimension: period_filtered_measures {
hidden: yes
description: "We just use this for the filtered measures"
type: string
sql:
{% if current_date_range._is_filtered %}
CASE
WHEN {% condition current_date_range %} ${created_raw} {% endcondition %} THEN 'this'
WHEN ${created_date} between ${period_2_start} and ${period_2_end} THEN 'last' END
{% else %} NULL {% endif %} ;;
}
# Filtered measures
measure: current_period_sales {
view_label: "_PoP"
type: sum
sql: ${sale_price};;
filters: [period_filtered_measures: "this"]
}
measure: previous_period_sales {
view_label: "_PoP"
type: sum
sql: ${sale_price};;
filters: [period_filtered_measures: "last"]
}