Vertical reference line in Google Data Studio line chart

Viewed 3030

I'd like to add a vertical reference line in a line chart at the position of the current month. Any way to do this?

Current chart: Chart without vertical reference line

Desired chart: Chart with vertical reference line

Thanks!

2 Answers

The Calculated Field below (where Date represents the name of the Date field, and Metric, the name of the current metric) adds a Bar on the current month:

1) Data Tab

  • Chart: Time Series
  • Dimension: Date; Type: Year Month
  • Metric #1: Metric
  • Metric #2: Today
IF(DATETIME_TRUNC(Date, MONTH) = DATETIME_TRUNC(TODAY(), MONTH), 1, NULL)

2) Style Tab

  • Metric #1: Line; Axis: Left
  • Metric #2: Bar; Axis: Right

3) Remove Right Y-Axis

  • Right Y-Axis (Custom Tick Interval): 1
  • Shape: Add a shape over the 0 to hide the last visible value of the Right Y-Axis

Editable Google Data Studio Report (Embedded Google Sheets Data Source) and a GIF to elaborate:

You can use this example below (borrowed from here). After you change the date to a number, you can put this new value on the right axis and make it a bar.

CASE
  WHEN CAST(FORMAT_DATETIME("%Y%m%d", Date) AS NUMBER ) = [YOUR DESIRED DATE] THEN 1
  ELSE 0
END
Related