The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi everyone,
A power BI newbie here.
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 Novmeber 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 how to write the correct dax here. I am totally out of ideas
@Anonymous , You have to follow this independent table approch
When I use this approach, I cannot have an appropriate legend. What I want to create is the following.
Suppose the slicer selection is November, so what should be seen in the visual is a line for November 2019 - November 2020 and then a differnt line for November 2018 to November 2019, with legend text as "current year" and "previous year". Otherwise it looks like this
@Anonymous , try measures like
Last 12 =
var _max = maxx(allselected([IDate]), 'IDate'[Date])
var _min = date(year(_max)-1,month(_max),1)
return
calculate(sum(table[value]), filter('Date', 'Date'[Date] >= _min && 'Date'[Date] <=_max))
Last 12 to Last 12 =
var _max1 = maxx(allselected([IDate]), 'IDate'[Date])
var _max = eomonth(date(year(_max1)-1,month(_max1)-1,1),0)
var _min = date(year(_max)-1,month(_max),1)
return
calculate(sum(table[value]), filter('Date', 'Date'[Date] >= _min && 'Date'[Date] <=_max))
where Idate is independent date table