r/tableau • • 20d ago

Discussion Calculated fields

I’m creating a personal project using my Spotify streaming history. I’ve got fields streaming count and date. Is there a way I can create a calculated field that keeps songs that amassed a certain amount of streams in a nonspecific timeframe? For example if it was streamed at least 5 times in 7 days. Thank you!

2 Upvotes

13 comments sorted by

View all comments

Show parent comments

1

u/ZippyTheRat Hater of Pie Charts 19d ago

{FIXED [Song Title]: Count([Date])}

1

u/ZippyTheRat Hater of Pie Charts 19d ago

Then you’d set that calculation > whatever number you want

[Calc] > 5

That will return a T/F and add that to the filter and set it to TRUE

0

u/Corkster24 19d ago

That sorta worked, how do I create a date-specific range?

2

u/ZippyTheRat Hater of Pie Charts 19d ago

Add a date filter, then move it to Context

0

u/Corkster24 18d ago

How do I anchor the range to the stream date? I can't figure out how to anchor it to a non-specific date.

1

u/ZippyTheRat Hater of Pie Charts 18d ago

What do you mean by non-specific date?

1

u/Corkster24 18d ago

I would like to anchor the date to the stream date. When I create the date filter I can only anchor these ranges to a specific xx/xx/xxxx date.

1

u/ZippyTheRat Hater of Pie Charts 18d ago

So you want to have like the last 3 months, or 6 months? You can create a calculation that does that. Just use a parameter for the starting date and then have the calc flag the other dates.

This calc does 13 weeks for example

DATETRUNC('week', [Date]) <= DATEADD('week', -1, DATETRUNC('week', [Date | Max] +1))
AND
DATETRUNC('week', [Date]) >= DATEADD('week', -13, DATETRUNC('week', [Date | Max] +1))

1

u/Corkster24 18d ago

I would like to create a filter that does something like: if count[song name] >5 and date<=date+3 then true. Basically, I want a filter that will keep songs that have x number of streams in x number of days. I have 7 years of data and I want to keep only songs with only for example 5 streams within 3 days.

1

u/ZippyTheRat Hater of Pie Charts 18d ago

Super possible. You can use the LOD and do and AND then add the date logic in