Have you ever wanted to calculate month to date and year to date profit when you have data across many dates in a table? As you may or may not already know, this is easy to do within Sigma!
But what if you wanted to compare these values year over year in the same table? Now, that’s a little bit trickier. It requires using some advanced Lookup functions.
In this post, I’ll provide an example with all the steps you need to follow to accomplish the aforementioned.
Let’s get started…
(A) Create a new table using the Plugs Electronics Hands On Lab data
I chose to rename this table “Plugs Electronics HOL Data
” (so you’ll see/use this in later formulas).
(B) Set up your groupings
(1) Create a grouping called [Year of Date]
with the formula: Year([Date])
- Sort this column in descending order
(2) Create a grouping called [Month of Date]
with the formula: Month([Date])
- Sort this column in ascending order
(3) Create a grouping called [Day of Date]
with the formula: Day([Date])
- Sort this column in ascending order
(C) Set up your calculations
Under the [Day of Date]
grouping level:
(1) Create a new column called[Daily Profit]
with the formula:
Sum([Price] * [Quantity] - [Cost])
(2) Create a new column called [Month to Date Profit]
with the formula:
CumulativeSum([Daily Profit])
(3) Create another new column called [Previous Year's Month to Date Profit]
with the formula:
Lookup([Month to Date Profit], [Year of Date], [Year of Date] + 1, [Month of Date], [Month of Date], [Day of Date], [Day of Date])
Under the [Month of Date]
grouping level:
(1) Create a new column called [Monthly Profit]
with the formula:
Sum([Daily Profit])
(2) Create a new column called[Previous Year's Monthly Profit]
with the formula:
Max([Last Year's Month to Date Profit])
(3) Create a new column called [Year to Date Profit]
with the formula:
CumulativeSum([Monthly Profit])
(4) Create a new column called [Previous Year to Date Profit]
with the formula:
Lookup([Year to Date Profit], [Year of Date], [Year of Date] + 1, [Month of Date], [Month of Date])
Finally…
The resulting table looks something like this:
Upon collapsing the [Month of Date]
grouping, we can more easily spot-check the lookup results:
Note that the table above doesn’t include any data past today’s date (it’s currently mid-November 2022). That said, as the days go on, the calculations for this month will change to account for new data.
Polishing it off…
Now, what if you wanted to visualize current month to date and year to date values compared to last year’s? In order to pull these insights from the parent table into the child visualization elements, you’ll need to use advanced lookup functions again. Note the differences in the Lookup formulas in the bonus steps below:
(D) Create visualizations
Current Month to Date Profit (vs. Previous Year’s MTD Profit)
(1) Create a child visualization element from the parent table. Choose the “Single Value” visualization type and un-select “Aggregate Values” in the “Value” section of the left-side panel.
(2) Add a new column to the “Value” section using the formula:
Lookup([Plugs Electronics HOL Data/Monthly Profit], Year(Today()), [Plugs Electronics HOL Data/Year of Date], Month(Today()), [Plugs Electronics HOL Data/Month of Date])
(3) Create a new column under the “Comparison” section using the formula:
Lookup([Plugs Electronics HOL Data/Previous Year's Monthly Profit], Year(Today()), [Plugs Electronics HOL Data/Year of Date], Month(Today()), [Plugs Electronics HOL Data/Month of Date])
Current Year to Date Profit (vs. Previous Year’s YTD Profit)
(1) Create a child visualization element from the parent table. Change the visualization type to “Single Value” and un-select “Aggregate Values” in the “Value” section of the left-side panel.
(2) Add a new column to the “Value” section using the formula:
Lookup([Plugs Electronics HOL Data/Year to Date Profit], Year(Today()), [Plugs Electronics HOL Data/Year of Date], Month(Today()), [Plugs Electronics HOL Data/Month of Date])
(3) Create a new column under the “Comparison” section using the formula:
Lookup([Plugs Electronics HOL Data/Previous Year to Date Profit], Year(Today()), [Plugs Electronics HOL Data/Year of Date], Month(Today()), [Plugs Electronics HOL Data/Month of Date])
Voila!
Just like that, you’ve got a template for year over year analysis. Feel free to use a similar workflow to analyze month to date and year to date cost, revenue, etc…
P.S. this could also be done through a join in a dataset… a topic for another time.