-1

EDITED (AGAIN): added tables and two screenshots (one of Google Sheets Chart and another showing mutliple issues in DS) to help demonstrate what I am seeing.

Short Version: I have created a parameter to help me score trending topics based on the date range filter. However, I want to be able to show a range of dates' worth of data, not just a specific date's worth of data. In theory, I could make the parameter a checklist with a huge range, but that doesn't seem efficient or sustainable down the road.

Disclaimer: I am about a week into SQL and Data Studio.

Long Version: We are tracking trends over time from a specific customer data set. I'd like to make it so that when a user adjusts the time range, various topics’ " score " depends on the end date. For instance, every time the topic "Recession" is brought up, it is given a score. That score is weighted based on when it was said. I was using 365 as the highest possible score so that anything over a year is null. So if "Recession" is referenced twice, once a week ago and once today, the avg score for recession is 361.5, but if a reference is made to the topic "Talent Management" twice today, then it would have a score of 365, and so forth across a growing list of 50+ topics pertaining to 50+ specific communities we are tracking the topics across.

Here is an example:

topics groups entry_date
recession A 2022-11-24
talent mgt A 2022-11-24
recession B 2022-11-22
economy A 2022-11-22
recession C 2022-11-15
talent mgt B 2022-11-8

This score would then affect the bubble size on a chart where the Y-axis is the count of unique groups referencing the topics, and an x-axis based on the range of average scores.

The goal is to be able to see which topics are the most common across groups, which ones are emerging trends, and which ones are dated trends by having a range slider. That way users (colleagues in other departments) can play with the date range "see" the bubbles moving in location and size.

example of static chart in google sheets

I could then also use the same data and fields to measure the percentage of topics being discussed across groups based on the weighted averages against a time range.

In Goolge Sheets I can do this with an xLookUp to a tab that has a column of 0-365 and then next to it a column of 365-0 (on a tab called 'scales') and then a cell on a sheet that you can put any date as the point in time, and it affects all the scores, tables, charts, etc. (I used. =xlookup((point_in_time - entry_date), 'scales'!A:A, 'scales'!B:B, "0")

In the data studios custom SQL I used:

SELECT
  *
FROM
  `qRaw_data'
where
    DATE(_entry_dates_) between
  parse_date('%Y%m%d', @DS_START_DATE) and
  parse_date('%Y%m%d', @DS_END_DATE)
AND
@pit_date_diff = date_diff(
    parse_date('%Y%m%d', @ds_end_date),
    _entry_dates_,
    day
  )

Then I created a field that is time_score of:

avg((Pit_Date_Diff-365)*(-1))

I have been googling and youtubing like crazy and think I either have to come up with a way to override the @pit_date_diff default value OR I need to use a CASE WHEN in the custom query where each time the date_diff is 1 then 365, and so on, but when I try that I get all sorts of errors.

I would like below to include all topics averaged based on all entry dates, not just those that correlate with the inputted parameter field.

currently, I can only show specific entry dates due to the parameter

I appreciate any and all help. I am a week into using data studio and am going cross-eyed Googling and YouTubing things. There is likely a better logical path to accomplish all this. Hoping for a holiday miracle.

Thanks in advance.

  • Taylor Luczak, [edit] with data, details & supplementary images so it's self contained ([Example](https://stackoverflow.com/q/72565176)) with ) Data: 3-9 rows of Inputs ([Markdown Table](https://meta.stackoverflow.com/a/403501)) with Sample Data set (Google: Sheets, Analytics, etc) ) Expected output table ) Chart: Configuration + Setup ) Issue: Attempt at solving + Output / Error ) Report: Publicly editable Looker Studio with 1-4. Without a [mre] it would be difficult to test suggestions & the issue could be [general troubleshooting](https://support.google.com/datastudio/faq/7219787) – Nimantha Dec 23 '22 at 04:31
  • edited and updated, hoping the screenshots help draw a better picture – Taylor Luczak Dec 23 '22 at 04:45
  • 1
    [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551) – Ken White Dec 23 '22 at 04:55
  • I updated it to show a demo table. The other image is of a chart in google sheets and the other is of DS showing multiple issues. – Taylor Luczak Dec 23 '22 at 05:11

1 Answers1

0

It turns out this was much easier than I realized... I added an AS syntax to create a column and then created a field that created the same metrics that I had in the Google Sheets:

SELECT
  *,
    (date_diff(parse_date('%Y%m%d', @ds_end_date), _entry_dates_,day)) AS q_time_diff
FROM
  `qRaw_data`

Then the score field is: (avg(q_time_diff)-365)*(-1)

In case that helps any others in the future... ¯\(ツ)

Happy Holidays!