Date Posted:
Product: TIBCO Spotfire®
Product: TIBCO Spotfire®
Problem:
How to add dynamic year-to-date (YTD) calculation in a cross table (as subtotals for rows)?
Solution:
If you have some monthly data in a cross table with the dates on the horizontal axis (e.g. Year > Month), and you want to see a year-to-date (YTD) column for each year in the cross table, you are essentially looking for a subtotals for rows. This article provides an option using data transformation and a simple data function to achieve this requirement. See the attached dxp file "Cross table subtotals for rows.dxp" for reference.
- Use data transformations to create two new columns [Year] and [Month] in your original data table.
- Go to Data < Transform Data < select your original data table < select Calculate new column for Transformations < Insert.
- Expression: Year([Date]); column name: Year < OK.
- Insert another Calculate new column for Transformations after the first one.
- Expression: Month([Date]); column name: Month < OK.
- Insert Change data types transformation as the third transformation.
- Change the data type of column [Month] from Integer to String. This is to add "YTD" to the column in the future.
- OK.
- Go to Data < Transform Data < select your original data table < select Calculate new column for Transformations < Insert.
- Go to Data < Data Function Properties < Register New to register a new data function.
- Define the data function: script: output = input
- input parameter: input, type: table, allowed data types: all
- output parameter: output, type: table
- Run the script.
- Define the parameters:
- input: columns ([Major Id], [Minor Desc], [Year], [Amount]); limit by: active filtering scheme
- output: Data table: create new data table: YTD.
- Check the box for "Refresh function automatically".
- Pivot the YTD table.
- Data < Transform Data < select YTD, and select Pivot for Transformations.
- Row identifiers: [Major Id], [Minor Desc], [Year]
- Column titles: None
- Values and aggregation methods: Sum(Amount); column naming pattern: %V
- OK < OK.
- Add rows from your original data table to the new YTD table.
- Match all 4 columns.
- Include additional columns from new data: choose column [Month].
- Identify origin of rows: Do not identify origin.
- OK.
- In the Data in analysis panel, locate the [Month] column in the YTD table. Click on the gear icon to see Details on selected column.
- Find Empty values.
- Replace empty values with: Specific value: YTD.
- Go to Data < Column Properties < find the [Month] column in the YTD table < Sort Order < Custom sort order < Configure.
- Order the values from 1 to 12, and YTD as the last one.
- OK.
- Create a cross table from table YTD.
- Horizontal Axis: add columns [Year] and [Month].
- Vertical Axis: add columns [Major Id] and [Minor Desc]
- Value Axis: Sum(Amount)
Comments
0 comments
Article is closed for comments.