[How to] Tableau Start-End Date Calculation to auto compare MOM on parameter

tableau start end mom

Background

I once had to do a visualization which requires users to select a certain month in a parameter i.e. 1 Dec 19 then the dashboard has to select data a whole month in December 19 vs. a whole month of November 19 in order to compare Month-over-month performance.

I googled and found Tableau calculation formula with a little customization. Hope this helps for those who struggle on the same problems!

[Calculation fields]: Current/Previous month, Start – End date

1. Create a parameter: `Month parameter` = 'Date' value 
Create calculation fields (No.2-9) as follow:

2. `Start Date current month`
DATETRUNC('month',[Month parameter])

3. `End Date current month`
DATEADD('second',-1,DATEADD('month',1,DATETRUNC('month',[Month parameter])))

4. `Start Date previous month`
DATEADD('month',-1,[Start Date current month])

5. `End Date previous month`
DATEADD('month',-1,[End date current month])

See the document how DATETRUNC(), DATEADD() work


Now, you can use below calculation to select current month ~ previous month and subtract them to find %Growth from previous month.

Calculation Fields Output

[Calculation fields]: %Growth MOM

5. is_current_month
[Date Column]>=[Start Date current month] AND [Date Column]<=[End Date current month]

6. is_previous_month
[Date Column]>=[Start Date previous month] AND [Date Column]<=[End Date previous month]

7. Current Sales
SUM(if is_current_month = TRUE then [Sales])

8. Previous Sales
SUM(if is_previous_month = TRUE then [Sales])

9. %growth MOM
((Current Sales - Previous Sales)/Previous Sales) * 100

Final Output


Related blog posts

Most of my blogs are in Thai but there is an Google Translate option inside the blog:

📊 Data Analytics — Tech, Programming Tutorial blog

🏀 Sport | 📺 Anime Review |🎧 Music | 🎬 Film Series | 📚 Book Review

tableau start end mom

Loading

GleeGM

My journal on personal life and interests including Data Analytics 📈, Books 📚, Music 🎶, Basketball 🏀, Figure Skating ⛸, Anime, Film 📺, Tarot, Lenormand, Uranian Astrology🔮

You may also like...