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
PowerBI101
Frequent Visitor

Extract and use slicer value as a filter for DAX formula (measure)?

My report consists of a line chart that is controlled by a date slicer (you pick the start and end date) and a few measures.

 

I have no issues with the line chart, but I would like to use the date slicer as a filter in the measure calculations. One measure could be called yearly incidents, where I use COUNTROWS() and some filters to calculate the incidents over a specific time period.

 

I would like to display the yearly number of incidents and this year would be controlled by the date slicer. For example, picking a end date of 30.5.2019 would select 2019 to be used as the filter and the measure calculation would include all events from this year (until today). Even if we picked a start date of 1.5.2019, the measure still needs to display all incidents from this year. So, the date slicer can't be linked to the measure card in interactions.

 

I tried to extract the year by using 

YEAR(LASTDATE(ALLSELECTED('Date'[Date]))), but it did not work (always returns the last year in my Date table). I assume that after I can correctly extract the ending year, I can use https://community.powerbi.com/t5/Desktop/Using-a-Measure-as-a-filter-in-DAX-formula/td-p/395330 to create the calculation.

 

What would be the best way to implement this? I'm using DirectQuery if that impacts something (I could always switch over to Import if needed).

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

In the filter portion of the CALCULATE() function, try this

DATESBETWEEN('Date'[Date],DATE(YEAR(MIN('Date'[Date])),1,1),TODAY())

Does this work?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @PowerBI101 ,

Have you solved your problem?

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

If you still need help, please share your data sample and your desired output.

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Ashish_Mathur
Super User
Super User

Hi,

In the filter portion of the CALCULATE() function, try this

DATESBETWEEN('Date'[Date],DATE(YEAR(MIN('Date'[Date])),1,1),TODAY())

Does this work?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @PowerBI101 ,

To understand your scenario better, could you share some data sample which could reproduce the scenario and your desired output so that we could help further on it?

Best Regards,

Cherry

Community Support Team _ Cherry Gao
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.