Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tejaswi08
Regular Visitor

undefined

Hi , 

 

I am trying to achieve something and finding few difficulties in it. Any suggestions/help on it would help me a lot.

 

I have a date slicer(to select year) and a line chart showing metric value(month wise, having year in legend). Expectation is to have 2 years value (Selected & Previous year) from the year selected from the slicer. 

 

Eg; If I select 2017 in the slicer. Line chart must show value for 2016 & 2017 month wise.

 

I have basically calculated the metric value as below,

 

start_date = max(date)

end_date = FIRSTDATE( DATEADD( [date],-1,YEAR))  (OR) 

Value_2years = CALCULATE( SUM([Value]) , DATESBETWEEN( [Date] , [start_date] , [end_date] ) )

 

When I see the value alone or with some other dimension , it is working good. But when I see it along with date(which is in the slicer) only one year data is getting popuated.

 

The input from the slicer was taken to calculate start and end date on fly. But we dont need  that input to filter visual.

 

Is there any work around for this?

 

Thanks in Advance!

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

Hi @tejaswi08,

In your scenario, firstly, create a Year table listing years(2011,2012,2013,2014,2015,2016,2017…), but don’t create any relationship between this Year table and your original table.

Secondly, in your original table(take sales table for example), create a year column using following DAX.

Year = YEAR(Sales[DateKey])

Then create a measure in your original table using DAX below.

CheckMeasure = IF(MAX(Sales[Year])>(MAX(Year[Year])-2) && MAX(Sales[Year])<=MAX(Year[Year]),1,0)

Thirdly, create a slicer using your Year table, and drag the CheckMeasure to the Visual level filters of your Line chart and filter the measure to 1 only. This way, when you select 2017 in the slicer, Line chart will show value for 2016 & 2017. You can review the following example for more details.
1.PNG


Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yuezhe-msft
Employee
Employee

Hi @tejaswi08,

In your scenario, firstly, create a Year table listing years(2011,2012,2013,2014,2015,2016,2017…), but don’t create any relationship between this Year table and your original table.

Secondly, in your original table(take sales table for example), create a year column using following DAX.

Year = YEAR(Sales[DateKey])

Then create a measure in your original table using DAX below.

CheckMeasure = IF(MAX(Sales[Year])>(MAX(Year[Year])-2) && MAX(Sales[Year])<=MAX(Year[Year]),1,0)

Thirdly, create a slicer using your Year table, and drag the CheckMeasure to the Visual level filters of your Line chart and filter the measure to 1 only. This way, when you select 2017 in the slicer, Line chart will show value for 2016 & 2017. You can review the following example for more details.
1.PNG


Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.