2 Replies Latest reply on Aug 13, 2018 10:14 PM by Mahfooj Khan

# How to create a line graph that compares previous year MTD vs current year MTD

Hi, I have daily sales data starting from 2017 up until the most recent date (Aug 13th, 2018) which gets updates every day as sales numbers come in.

I have created a line graph shown below which shows the Total month sales until August for 2017: orange line

Also, a line graph that shows the MTD sales for August 2018: blue line

To achieve this, I have created a filter called validation with the calculations:

DATEPART('month',[Date])<=DATEPART('month',[Max Date in Data Set])

The problem with the current graph is that it is comparing the entire sales data for August 2017 against MTD sales data for August 2018 which ends up making the August 2018 line (blue line) way lower than its counterpart.

Now, I want to be able to compare the MTD sales for 2017 vs MTD sales for 2018, is there a way to achieve this?

I have attached an example file of what I did using superstore sample data from 2012 to 2013 August 13th:

Thank you

• ###### 1. Re: How to create a line graph that compares previous year MTD vs current year MTD

Hi John,

Try this, it should work.

(DATEPART('month',[Order Date])<DATEPART('month',[Max Date in Dataset])) OR

(DATEPART('month',[Order Date])=DATEPART('month',[Max Date in Dataset]) AND DATEPART('day',[Order Date])<=DATEPART('day',[Max Date in Dataset]))

• ###### 2. Re: How to create a line graph that compares previous year MTD vs current year MTD

Hi,

Find my appraoch below

Create two calculated field like this

CY-MTD:

IF [Order Date]>=DATETRUNC('year',{MAX([Order Date])})

AND [Order Date]<={MAX([Order Date])}

THEN [Sales]

END

PY-MTD:

THEN [Sales]

END

Then drag the fields like this and check

Let us know if this help.

Mahfooj