Calculation to display Selected month and Previous month|| Datetrunc & Dateadd

Опубликовано: 22 Октябрь 2024
на канале: Tableau Tip
22,394
143

Provide an option to choose month-year to user
and display selected month value and
previous month value

-----
For suppose,
when user selects
May 2018 - need to display may and apr values

Create parameter with date as datatype

Calculated filed to display selected month


datetrunc -
returns the starting value based on the
datepart


order date format: mm/dd/yyyy


dateadd('month',-1,[Choose Month-year]) -
returns previous month

selected month
if DATETRUNC('month',[Order Date])=DATETRUNC('month',[Choose Month-year]) then [Sales] END

previous month
if DATETRUNC('month',[Order Date])=DATETRUNC('month', dateadd('month',-1,[Choose Month-year])) then [Sales] END