Tableau - data contains start / end date, how to make a fixed access for every month between?

为君一笑 提交于 2019-12-11 05:31:46

问题


I have an extremely similar issue / set of data as the person from this post ..

Tableau month-based bar chart for data with date range

however the accepted solution doesn't realistically work for my case. They suggested making 12 calculated fields, one for each month, and pivot and display.

The 2 issues I run into with this, is my data spans across 6 years 1. So 6 years x 12 months would be 72+ calculated fields 2. Also, for each additional new month, I'd have to manually create a new calcualted field

My data looks like this:

name   | start      | end        
john   | 2015-01-15 | 2018-03-30 
tim    | 2016-02-01 | 2017-05-15 
brian  | 2017-02-15 | 2018-04-01 

Is there a way in tableau, to have one of the axis show every single month from the min (start date) and max (end date), so that I can tally a total for each month?

UPDATE ** As far as a metric, it would just be a "Number of Records" count. Basically what I'm looking based on each persons start and end date, create a tally for EVERY month, showing how many employees we had for that specific month, so the output would look like (axis could be either way):

          Number of Employees
Jan 2015         3
Feb 2015         5
Mar 2015         6
  .              4
  .              5
  .              8
  .              7
Sep 2016         10
Oct 2016         13 
  .              12
  .              15 
  .              15
  .              15
Apr 2017         18
 etc...        

Help or guidance would be greatly appreciated on this!

Thanks


回答1:


With a little help fron @Sam M on what to search for, I came across a youtube video that basically gave me exactly what I was looking to do (the video does it by week, I just tweeked the formulas to month)

https://www.youtube.com/watch?v=gZ9p-hV6-qM

Thank you all!




回答2:


Another approach could be to pivot data and then use running sum to calculate the number of employees in each month.

Let's start with your sample data

Name    Start Date  End Date
John    2015-01-15  2018-03-30 
Tim     2016-02-01  2017-05-15 
Brian   2017-02-15  2018-04-01 


Steps to follow in Tableau:

  • Pivot input data to have it in below format

Name  Pivot Field Names  Pivot Field Values
John  Start Date         2015-01-15
Tim   Start Date         2016-02-01 
Brian Start Date         2017-02-15
John  End Date           2018-03-30
Tim   End Date           2017-05-15
Brian End Date           2018-04-01

  • Create a calculated field Employees Count as

ZN(IF([Pivot Field Names]='Start Date') THEN [Number of Records] END) -
  ZN(IF([Pivot Field Names]='End Date') THEN [Number of Records] END)

  • Drag Pivot Field Values in "Columns" section. Right click it to select Month MMM YYYY format which converts it to continuous.

  • DragEmployees Count in Rows section. Right click it to select "Quick Table Calculation" as "Running Total" to have the computation using Table(across) and Voila!



来源:https://stackoverflow.com/questions/53546485/tableau-data-contains-start-end-date-how-to-make-a-fixed-access-for-every-m

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