10 Replies Latest reply on May 15, 2015 9:16 AM by dinesh reddy

# I am not able to get Current Month and Previous Month from a date parameter

hi

I am using a date parameter one  for start date and one for end date and i need two fields to be displayed one is for current month data and another one is for previous month data and it should change accordingly to my start and end dates parameter

• ###### 1. Re: I am not able to get Current Month and Previous Month from a date parameter

My answer is assuming your start date parameter is the previous month, and your end date would be the current month.

Create a calculated field like the following (Since you are looking for months)

DATETRUNC('month', [Date]) = DATETRUNC('month', [Start Date Parameter])

OR

DATETRUNC('month', [Date]) = DATETRUNC('month', [End Date Parameter])

Place this on your filter shelf and select True.

IF your Start and End Date Parameters are something different, please let me know and I would be happy to help.

Regards,

Rody

• ###### 2. Re: I am not able to get Current Month and Previous Month from a date parameter

if start date and end date are same means what will happen

• ###### 3. Re: I am not able to get Current Month and Previous Month from a date parameter

You would only show the month that the start and date are.

So in this case, you would take it a step further.

IIF(

DATETRUNC('month', [Start Date]) = DATETRUNC('month', [End Date]),

(

DATETRUNC('month', [Date]) = DATETRUNC('month', [End Date ])

OR

DATETRUNC('month', [Date]) = DATETRUNC('month', DATEADD('month', -1, [End Date]))

)

,

(

DATETRUNC('month', [Date]) = DATETRUNC('month', [Start Date])

OR

DATETRUNC('month', [Date]) = DATETRUNC('month', [End Date])

)

)

Regards,

Rody

• ###### 4. Re: I am not able to get Current Month and Previous Month from a date parameter

That would ensure that you are always showing the previous month.

How would you like to handle situations where the user selects a start date of 2015-01-01 and an end date of 2015-04-01?

The previous calc would show January and April. I can adjust that, but it all depends on what you want the user to see.

Regards,

Rody

• ###### 5. Re: I am not able to get Current Month and Previous Month from a date parameter

the user want use the present month and previous month only and i want % change

(previous month - present month )/ present month

• ###### 6. Re: I am not able to get Current Month and Previous Month from a date parameter

Ok, so let's take it one step further than.

IIF(

DATETRUNC('month', [Start Date ]) = DATETRUNC('month', [End Date]),

(

DATETRUNC('month', [Date]) = DATETRUNC('month', [End Date])

OR DATETRUNC('month', [Date]) = DATETRUNC('month', DATEADD('month', -1, [End Date]))

)

,

IIF(

DATEDIFF('month', DATETRUNC('month', [Start Date ]),DATETRUNC('month', [End Date])) > 1,

(

DATETRUNC('month', [Date]) = DATETRUNC('month', [End Date])

OR DATETRUNC('month', [Date]) = DATETRUNC('month', DATEADD('month', -1, [End Date]))

)

,

(

DATETRUNC('month', [Date]) = DATETRUNC('month', [Start Date ])

OR

DATETRUNC('month', [Date]) = DATETRUNC('month', [End Date])

)

)

)

This should allows show the current and the previous month.

Except in an instance where the user select 2015-04-01 as the Start Date and 2015-02-01 as the End Date, i.e. not logical.

Hope this helps,

Rody

• ###### 7. Re: I am not able to get Current Month and Previous Month from a date parameter

And as far as the (previous month - present month )/ present month %change

You could use a lookup function, i.e.

( LOOKUP(SUM([Sales])) - SUM([Sales])), FIRST())) / SUM([Sales])

• ###### 8. Re: I am not able to get Current Month and Previous Month from a date parameter

Am I getting closer, or further away from what you are looking for?

Regards,

Rody

• ###### 9. Re: I am not able to get Current Month and Previous Month from a date parameter

Here is a workbook example.

-Rody

• ###### 10. Re: I am not able to get Current Month and Previous Month from a date parameter

sample data

i want output like this in tableau

<1 day is a condition

and % age change is based on (current month - previous month)/previous month

current month is (< 1 day current month and 1-<2day ciurrent month )/ total current month .

that values(under current and previous month) are count distinct of a sourcerequest id

can you help on this rody