知識庫

How to show current month values with start and end dates of the month in the header


發佈時間 : 31 Jan 2020
上次修改日期 : 21 Oct 2022

問題

How to show current month values with start and end dates of the month in the header

環境

  • Tableau Desktop

答案

1. Create a calculated field called Current month value with the following formula:
    If DATEDIFF('month',[Order Date],TODAY())=0 then [Value] end

2. Create the view like below with the Field in rows and calculated field value as a Measure value:

User-added image

3. Right click the Measure name value and deselect the Show header option:
User-added image

4. Open a new sheet and Create calculated fields like below for start and end dates of month:

Name of calculated field: Start of current month
Formula: If DATEDIFF('month',[Order Date],TODAY())=0 then DATETRUNC('month',[Order Date]) end

Name of calculated field: Last date of current month
Formula: If DATEDIFF('month',[Order Date],TODAY())=0 then DATEADD('second',-1,DATEADD('month',1,DATETRUNC('month',[Order Date]))) end

5. Drag the above created calculated fields to Rows to place them beside each other with start of current month field being the field on left.
6. Right click the field on Rows shelf and choose Custom Date representation as below:
User-added image

7. Drag another instance of the Start of current month and Last date of current month to filter and choose the Non Null value.
8. Create a calculated field Empty with the formula :  " " 
9. Drag the Empty calculated field to text on Marks Card.
10. Create a field like "to" in between the Start of current month and Last date of current month fields on Rows shelf as shown in the screenshot below:
User-added image
11. Open a new dashboard and drag the sheet with view first.
12. Change to Floating instead of the Tiled Layout and drag the start and end sheet to the position of the header by adjusting the width of the view accordingly.

Below is the final output generated:

User-added image
這篇文章是否解決了問題?