0
votes

Table which I have has month-wise counts from July,2018. Data goes untill December 2020.

I have a slicer which selects the month and the year for the other visuals on the page.

I need to create a line chart which dynamically shows last 2 years of data or 24 months of data. So say suppose if I select, November 2020 from slicers, I need to see a graph that starts from November 2018 and ends at Novemberenter image description here 2020. I need to have a text - "Current year" and "Previous Year" in the legend which is also another challenge that I am facing.

Below is the image for reference.

Please help me write the correct DAX

1
You need to write a measure that will filter dates for the desired period. Have a look at CALCULATE, DATESBETWEEN ans SAMEPERIODLASTYEAR. you may also want to look at calculation groups, which will make it easy to put current vs previous year in the legend.W.B.
And also, as is the custom at stackoverflow, please show what is your approach, what have you tried so far and where you are having trouble.W.B.

1 Answers

0
votes

Maybe DAX is not the only option. You could try using a filter with 'relative date'. Microsoft documentation relative date