
For the challenge this week, Yoshi wanted us to recreate this summary KPI card detailing the latest Profit Ratio, the change from the previous day, and comparisons against equivalent timeframes.
Defining the calculations
In a usual scenario, we would utilise the TODAY() function to base the rest of the measures being displayed. However given the dataset we’re using and the desire to ensure the viz doesn’t eventually display nothing on my Tableau Public page, ‘Today’ will be harded coded in the parameter
pToday
date parameter defaulted to 04 Feb 2025.

We have 3 timeframes we need to visualise, so we need to find the dates these relate to
Today Last Month
DATE(DATEADD(‘month’, -1, [pToday]))
Today Last Year
DATE(DATEADD(‘year’, -1, [pToday]))
I also want to group these ‘timeframes’ and created
Recent | Prior Mth | Prior Yr
IF [Order Date] >= DATEADD(‘day’, -14, [pToday]) AND [Order Date] <= [pToday] THEN ‘Recent’ ELSEIF [Order Date] >= DATEADD(‘day’, -14, [Today Last Month]) AND [Order Date] <= DATEADD(‘day’, 14, [Today Last Month]) THEN ‘Prior Month’ ELSEIF [Order Date] >= DATEADD(‘day’, -14, [Today Last Year]) AND [Order Date] <= DATEADD(‘day’, 14, [Today Last Year]) THEN ‘Prior Year’
ELSE NULL
END
Add this to Rows on a sheet , then add Order Date as a discrete exact date (blue pill). Add Recent | Prior Mth | Prior Yr to Filter and exclude Null. All the dates we want to plot will be displayed against their relevant ‘category’

Create a new field
Profit Ratio
SUM([Profit]) / SUM([Sales])
and format to % with 1 dp
Additionaly create fields
PR -Recent
IF MIN([Recent | Prior Mth | Prior Yr]) = ‘Recent’ THEN [Profit Ratio] END
and
PR – Not Recent
IF MIN([Recent | Prior Mth | Prior Yr]) <> ‘Recent’ THEN [Profit Ratio] END
and format these to % with 1dp too.
Add these 3 fields into the table

Finally we need to create the field for the x-axis based on the number of days, so create
X-Axis
CASE [Recent | Prior Mth | Prior Yr]
WHEN ‘Recent’ THEN DATEDIFF(‘day’,[pToday],[Order Date])
WHEN ‘Prior Month’ THEN DATEDIFF(‘day’,[Today Last Month],[Order Date])
WHEN ‘Prior Year’ THEN DATEDIFF(‘day’,[Today Last Year],[Order Date])
END
Add this onto Rows

Now we have the core fields needed for the line chart.
Building the Line Chart
On a new sheet, add Recent | Prior Mth | Prior Yr to Filter and exclude NULL. Then add X-Axis as a continuous (green) pill to Columns and PR – Recent to Rows. Add Recent | Prior Mth | Prior Yr to Colour. The add PR-Not Recent to Rows. Make the chart dual axis, synchronise the axis and then remove Measure Names from the All marks card. Adjust the colour legend associated to the Recent | Prior Mth | Prior Yr field.

Reorder the pills on the Rows so PR-Not Recent is first, which makes the ‘recent’ line in front of the others.
On the PR-Not Recent marks card, adjust the Path, to be a dashed line. On the PR-Recent marks card, add circle line markers (via the colour shelf options). Hide the right hand axis, and hide the null indicator

On the All marks card, add Profit Ratio to the Tooltip shelf and also add Order Date as a discrete exact date (blue bill) to Tooltip. Adjust to suit.
The Hide the X-Axis (uncheck show header), remove the title of the Y-axis, remove row & column dividers and vertical gridlines.

Building the KPI Card
Create new fields
PR-Today
{FIXED:SUM(IF [Order Date]=[pToday] THEN [Profit] END)}/{FIXED:SUM(IF [Order Date]=[pToday] THEN [Sales] END)}
format to % with 1 dp
PR-Yesterday
{FIXED:SUM(IF [Order Date]=DATEADD(‘day’, -1,[pToday]) THEN [Profit] END)}/{FIXED:SUM(IF [Order Date]=DATEADD(‘day’, -1,[pToday]) THEN [Sales] END)}
format to % with 1 dp
PR – Difference
[PR – Today] – [PR – Yesterday]
format to % with 1 dp
PR Direction Up
IF [PR Difference]>=0 THEN ‘Up’ END
PR Direction Down
IF [PR Difference]<0 THEN ‘Down’ END
On a new sheet add PR Difference, PR Direction Up, PR Direction Down, PR-Today and pToday to the Text shelf. Set the mark type to shape and use a transparent shape (see here for details on how to set this up). Then adjust the text as required, formatting as necessary and add a title that references pToday

The add these two sheets to a dashboard and you’re done. My published viz is here.
Happy vizzin’!
Donna






























































































































