Forum Discussion

sgeheeb's avatar
sgeheeb
Icon for Resolver I rankResolver I
6 years ago

Trailing 12 Months issue

Hi,

 

I am trying to to build a line chart showing a company's sales over the prior 12 months, starting with the last full month. So today being 2nd July, the line chart would display data for June 2019 to June 2020.

 

First of all, I am struggleing with the measure: The following should be working, but produces the wrong results:

 

12 M =
VAR _EndDate =
    DATE ( YEAR ( LASTDATE ( dSalesOrderInsertedDate[Sales_Order_Insert Date] ) ), MONTH ( ( LASTDATE ( dSalesOrderInsertedDate[Sales_Order_Insert Date] ) ) ) - 1, 1 )
VAR _StartDate =
    DATE ( YEAR ( LASTDATE ( dSalesOrderInsertedDate[Sales_Order_Insert Date] ) ) - 1, MONTH ( ( LASTDATE ( dSalesOrderInsertedDate[Sales_Order_Insert Date] ) ) ) - 1, 1 )
RETURN
    CALCULATE (
        [Sales Amount],
        DATESBETWEEN (
            dSalesOrderInsertedDate[Sales_Order_Insert Date],
            _StartDate,
            _EndDate
        )
    )

 

 

If a use a measure, which simply calcualtes the trailing twelve month from the current date I still run into problems:

 

The measure:

 

12 M (incl. today) =
CALCULATE (
    [Sales Amount],
    DATESINPERIOD (
        dSalesOrderInsertedDate[Sales_Order_Insert Date],
        LASTDATE ( dSalesOrderInsertedDate[Sales_Order_Insert Date] ),
        -1,
        YEAR
    )
)

 

 

If I only select a Year on the date-slicer, things look like this :

this shows the full year 2019, but from January to December. I need it to display July 2019 to July 2020.

 

If I use another date slicer to select a month (e.g. July), the line-chart only displays the selected month:

 

I get that this seems to be the default behaviour, but I need the chart to display July 2019 to July 2020 (or, ideally June 2019 to June 2020)

 

Any help on the measure or a method to display the correct timespan would be greatly appreciated.

2 Replies