Loading

Displaying Active Records Over Time

Publiceringsdatum: Apr 24, 2025
Uppgift
If each record has an open and close date, how to display active records over time

For example, using the attached data set containing start/end dates for each client, how many clients were active on August 4, 2021?
Steg

Option 1: Use Date Scaffolding

Create a table that contains a list of all possible dates, which will be joined to the original data connection. In this example, that table is called "Date List".

  1. Navigate to Data > {original data source} > Edit Data Source...
  2. Click "Add" and connect to the "Date List" table
  3. Drag the "Date List" table to the canvas area
  4. In the Edit Relationship dialog, do the following:
    1. Under Contracts, select [Open Date]
    2. Under Date List, select [Date]
    3. Click the equal sign, and select <= and click Close
    4. Click "Add more fields"
    5. Under Contracts, click "Create Relationship Calculation..."
    6. In the Relationship Calculation dialog, type IFNULL([Close Date],TODAY()) and click OK
    7. Under Date List, select [Date]
    8. Click the equal sign, and select >=
  5. Navigate to a new worksheet
  6. Right-click and drag [Date] to the Columns shelf
  7. In the Drop Field dialog, select Date (continuous) and click OK
  8. Drag [Contracts (Count)] to the Rows Shelf

 

Option 2: Use Tableau Prep Builder to fills gaps 

Starting in Tableau Prep Builder 2021.3.1, you can create a step to add rows for every day (or other date level) between the start and end date. See Fill Gaps in Sequential Data for instructions. 

In Tableau Prep Builder

  1. Connect to the original data source
  2. Drag the Contracts table onto the canvas
  3. Hover over the input step and click the plus sign and select Clean Step
  4. Click on Clean 1 to select the step
  5. In the clean step, click Create Calculated Field
  6. In the Add Field Dialog do the following:
    1. Name the Field Close Date
    2. Type in the formula: DATE(IFNULL([Close Date],TODAY()))
  7. From Clean 1, add a New Rows step
  8. In New Rows 1, do the following:
    1. Select Value ranges from two fields
    2. Tableau1.png

    3. Select Open Date <= Close Date
    4. Name the field Date
    5. For What values should your new rows have, select Copy from previous row
  9. Output the data


In Tableau Desktop

  1. Connect to the output
  2. Right-click and drag [Date] to the Columns shelf
  3. In the Drop Field dialog, select Date (continuous) and click OK
  4. Drag [Extract (Count)] to the Rows Shelf


Option 3: Create Calculations

 

Step 1: Define the beginning of the period

  1. Select Analysis > Create Calculated Field
  2. Name the field Start Date, enter the following calculation, and click OK: 
    DATETRUNC('week',WINDOW_MIN(MIN([Date])))
  3. Select Analysis > Create Calculated Field.
  4. Name the field Running Date, enter the following calculation, then click OK:
    DATEADD('week',(INDEX() - 1),[Start Date])
 

Step 2: Define the duration of the period 

  1. Select Analysis > Create Calculated Field.
  2. Name the field isActive, enter the following formula, then click OK: 

    IF [Running Date] >= WINDOW_MAX(MAX([Date]))
    AND [Running Date] <= WINDOW_MAX(MAX([Closed Date]))
    THEN 1
    ELSE 0
    END

 

Step 3: Determine the active items

  1. Select Analysis > Create Calculated Field.
  2. Name the field Number of Active Contracts, enter the following formula, then click OK: 
    IF INDEX() = 1 THEN WINDOW_SUM([isActive])END
 

Step 4: Build the view 

  1. Drag Date to Columns
  2. On Columns, right-click Date and select Week Number.
  3. Right-click Date again and select Discrete.
  4. Right-click any week header, and select Show Missing Values.
  5. Drag Client to Detail.
 

Step 5: Configure table calculations and complete the view 

  1. Drag Start Date to Detail
  2. On Detail, right-click Start Date and select Edit Table Calculation
    • Under Compute Using, select Specific Dimensions.
    • Check the boxes next to Week of Date and Client, then close the Table Calculation dialog box. 
  3. Drag Running Date to Detail
  4. On Detail, right-click Running Date and select Edit Table Calculation.
    • Under Compute Using, select Specific Dimensions
    • Move Client above Week of Date.
    • Check the boxes next to Client and Week of Date
    • Under Restarting Every, select Client, then close the Table Calculation dialog box. 
  5. Drag isActive to Detail
  6. On Detail, right-click isActive, then select Compute Using > Date
  7. Drag Number of Active Contracts to Rows
  8. On Rows, right-click Number of Active Contracts, and select Edit Table Calculation
    Check the box next to Client, uncheck Week of Date if it is checked, then close the Table Calculation dialog box. 

*Optional: To include records that have no closed date, use IFNULL() to convert the NULL values in the [Closed Date] field to some arbitrary future date:
IFNULL([Closed Date],#1/1/2999#)

  • To view the steps showed in the below video, please expand the above section.
    Note: the video has no sound.
  •   
Ytterligare resurser
The above instructions use the "Contracts" and "Date List" in the attached Sample Data.xlsx file.
 
Knowledge-artikelnummer

001458045

Bilagor

sample date scaffolding flow.tfl

4 KB

Sample Data.xlsx

18 KB

Displaying Active Records_v2020.3.twbx

72 KB

 
Laddar
Salesforce Help | Article