For the Salesforce Dreamforce (#DF22) conference, Lorna set this challenge based on using Salesforce data. You could access the data either by creating a Salesforce Developer account, or using the provided csv data set. I chose to use the latter.
I’m not overly familiar with the SF data, so it’s possible in the course of this blog, I may have missed a field in the data set that could have been used instead of whatever technique I describe. Feel free to let me know in the comments if this is the case.
Setting up the calcs
After connecting to the data, the first step was to amend the amount based on whether the Stage Name was ‘Closed Lost’ or not.
IF [Stage Name]=’Closed Lost’ THEN -1 * [Amount] ELSE [Amount] END
I set the format of this field to be Currency £M with 1 dp.
Now the crux of the waterfall, is that the position of the mark that needs to be plotted it is based on the cumulative sum of the values displayed. So for this we need to create a table calculation
Revised Amount (Running Total)
I set the format of this field to be Currency £M with 0 dp.
Let’s put the data into a table to see what’s going on.
The table calculation of the 2nd column (Revised Amount (Running Total)) is computing ‘down’ the table, so for this to work as we require the order of the rows is important. I just manually sorted by dragging each Stage Name into the relevant position. and then added a grand total.
With these 2 fields, we can now build the basic waterfall.
Build the Waterfall
I chose to duplicate the above sheet and then move the pills around as follows
- Move Stage Name to Columns
- Move Revised Amount (Running Total) to Rows. Amend the table calculation setting so it is set to explicitly compute using Stage Name.
- Change the Mark Type to Gantt Bar
- Move Revised Amount from Text to Size, then double click on the Revised Amount pill so it becomes editable and add * -1 to the end, to invert the value
- Add Row Grand Total
- Add Stage Name to Colour and manually adjust each colour accordingly
- Add Revised Amount to Tooltip and adjust.
- Edit Revised Amount (Running Total) axis (right click axis -> Edit Axis) and amend axis title
- Format the Grand Total label (right click label -> Format) and amend says ‘Total’ and is bold.
- Hide the Stage Name label at the top of the chart (right click label -> hide field names for columns)
Labelling the bars
Labelling the bars isn’t quite as simple as you think it might be, as the position of the label differs depending on whether the Revised Amount is positive (at the top) or negative (at the bottom).
So we need to create some new calculations
LABEL – +ve Revised Amount
IF SUM([Revised Amount])>=0 THEN SUM([Revised Amount])
formatted to £M to 1 decimal place
LABEL – -ve Revised Amount
IF SUM([Revised Amount])<0 THEN SUM([Revised Amount]) END
formatted to £M to 1 dp
Adding these to the tabular layout we had earlier you can see how these fields are behaving.
Switch back to the waterfall chart, and add LABEL – +ve Revised Amount to the Label shelf. Format the label to be smaller font (I chose 8pt), bold and explicitly aligned to the top.
Now duplicate the Revised Amount (Running Total) pill that is on Rows to add another instance directly next to it. I do this by holding down ctrl as I then click and drag the pill. This will create another axis.
On the second marks card, remove LABEL – +ve Revised Amount from Label and add LABEL – -ve Revised Amount instead. Adjust the label so it is aligned at the bottom instead.
Now make the chart dual axis and synchronise the axis.
Then hide the right hand axis, and remove all divider and gridlines.
Then add to the dashboard. I used a vertical layout container so I could add blanks of 1 pixel in height with a black background colour to present the this black lines separating the header and footer text.
My published viz is here.