Tableau, Week to Date, Month To Date, Year to Date parameter

久未见 提交于 2020-05-01 03:38:06

问题


I have a data set spanning 2 years and is updated daily, created a dashboard to give a view of incidents by date group. I have created a parameter using date trunc for Day/Week/Month/Quarter/Year. This is in Tableau.

I am trying to get the parameter to show a Week to date, Month to date and so on view. IE if on Weds 15th Dec I selected the weekly view, it would only show data for every week in the data set for Sat-Weds (My weeks go Sat-Fri) or the monthly view every month between 1st-15th

Ideally I am wanting this as a simple parameter for a drop down menu, I can do the week to date stuff as a rolling sum restarting every week in a separate table, but for ease I just need a date group function that will allow to do this.

Any suggestions would be appreciated.

Cheers

Pete


回答1:


The solution is 5 parts:

  1. Date Part Parameter
  2. Max date [Max Date]
  3. Dynamic date part of the Max date [Dynamic Date Part Max]
  4. Dynamic date part of the historical dates [Dynamic Date Part]
  5. Filter those date parts <= the Max date [Dynamic Date - Lass than Max]

Date Part Parameter

Max Date

This is the calculation you'd use with your dataset to find the max date.

{ MAX([Order Date]) }

In order to create a good example, I'm going to set my Max date to a specific date the falls in the middle of a week, in the middle of a month and middle of the year. I'm going use June 13th, 2018 as my Max Date.

So, if you want to follow along you can use the below date as your max date. You can also use this data set if you'd like.

DATE(#2018-06-13#)

Dynamic date part of the Max date

DATEPART([Select Date Part], [Max Date])

Dynamic date part of the Historical dates

DATEPART([Select Date Part], [Order Date])

Filter on Historical dates parts <= the Max Date

[Dynamic Date Part] <= [Dynamic Date Part Max]

Now that we have all the pieces we need let's check to make sure they are working as we would expect.

Looks like we're seeing all the days of the month that are <= the 13th.

When we change it to Day of the Week we see only the days of the week <= the 4th day of the week which is Wednesday when the week starts on Saturday.

Now let's calculate the running sum of sales along our dynamic date part to better help you with your example.

Drag the measure you want to calculate the running sum onto the label, then create a quick table calculation. We'll next need to edit this table calculation as so.

You'll then see your calculation working as you would expect.

Hope this was helpful. Happy vizzing!



来源:https://stackoverflow.com/questions/54169761/tableau-week-to-date-month-to-date-year-to-date-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!