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
deb_power123
Helper V
Helper V

How to filter and exclude rows based on date slicer maximum date range?

Hi Everyone,

 

I have a scenario where I have a table say Student table. I have the following columns as below: 

 

StudentIDStudentNameAdmissionDateLastAttendanceDateDateLeftLocationStudenttype

 

I created another calendar table with a range of dates on Dates column and related it to the Last AttendanceDate column of the Student table by 1:1 relation.

 

As per my scenario: If the maximum date range selected in date slicer is greater than the "Date Left" column value  then exclude that row from the visual else include it. For example :In the above case my maximum date selected is "15.05.2011" then the date left column has one date 14.05.2011 which is less than maximum selected date so this row should be filtered out and excluded from the table visual.

 

I need to write a DAX measure formula to calculate this and exclude the row which fulfills the above criteria , please provide your suggestions.Appreciate for all your inputs.

 

I wrote the below mesaure using Filter expression but it didnt work.

 

My Calculated Measure which is not working is as below:[I think i did something incorrect as i am not fluent in using FILTER function]

 M1 =  IF (SELECTEDVALUE 'Calendar'[Dates]>=MAX('Calendar'[Dates] ,FILTER(ALL('Student),'Student'[DateLeft]<=MAX('Calendar'[Dates])

 

My Calendar Table data :

Dates

01-05-2011
02-05-2011
03-05-2011
04-05-2011
05-05-2011
06-05-2011
07-05-2011
08-05-2011
09-05-2011
10-05-2011
11-05-2011
12-05-2011
13-05-2011
14-05-2011
15-05-2011

 

My Input Data is as below :

StudentIDStudentNameAdmissionDateLastAttendanceDateDateLeftLocationStudenttype
100Harry01-02-201010-05-2011 10:4501-06-2011LondonFullTime
101Sally01-02-201001-05-2011 16:45 LondonFullTime
103Mary01-02-201002-05-2011 12:45 LondonFullTime
104John01-02-201107-05-2011 09:4531-09-2011ParisFullTime
105Geeta01-04-201113-05-2011 12:45 AthensFullTime
106James01-02-201102-05-2011 12:45 AthensFullTime
107Marc01-02-201011-05-2011 12:4514-05-2011AthensPartTime
108Sam01-04-201102-05-2011 14:4502-10-2011TorontoPartTime
109Ravi01-04-201004-05-2011 12:45 TorontoPartTime
110Jose01-02-201108-05-2011 15:4503-08-2011TokyoFullTime

 

My Expected Output as below :[the one striked out should be removed since the maximum value of date selected is 15.05.2011 in date slicer and the DateLeft is 14.05.2011 which is less than selected date.so that row should be excluded and filtered out from final visualization. Since rest all values of Date left are greater than the Maximum date range selected in date slicer.

expected output.JPG

 

Regards

Sameer

1 ACCEPTED SOLUTION
v-yuaj-msft
Community Support
Community Support

Hi @deb_power123 ,

 

Have you forgotten to create a "calendar" table?

Measure = 

var x1=CALCULATE(MAX('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))

return

IF(DATEDIFF(MAX('student'[LastAttendanceDate]),x1,DAY)<0,1,0)
Result:

v-yuaj-msft_0-1615265235102.png

I don't think it can display the rows containing LastAttendedDate as null values. It will make errors.

 

Hope that's what you were looking for.

Best Regards,

Yuna

 

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

9 REPLIES 9
v-yuaj-msft
Community Support
Community Support

Hi @deb_power123 ,

 

Have you forgotten to create a "calendar" table?

Measure = 

var x1=CALCULATE(MAX('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))

return

IF(DATEDIFF(MAX('student'[LastAttendanceDate]),x1,DAY)<0,1,0)
Result:

v-yuaj-msft_0-1615265235102.png

I don't think it can display the rows containing LastAttendedDate as null values. It will make errors.

 

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

I too feel the same.It is not possible.Anyways thanks for all the helpful points

v-yuaj-msft
Community Support
Community Support

Hi @deb_power123 ,

 

Is the following result what you want? The remaining dates are only 10-5-2021, 12-5-2021 and 14-5-2021.

If not, please share your desired result with me based on your sample table. 

030901.gif

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

so, if i select a date range, 02-05-2011 to 08-05-2011 in date slicer, I should be able to show  the below results in my table visualization :-

1.JPG

I tried to copy paste the  data here but the forum rules doesnt let me do so.I attached the.pbix file in above reply

Hi ,

 

Can I display the rows containing LastAttendedDate as null values for date range as selected in the date slicer?

My pbix file is uploaded here , you can download it by clicking the link below:-

https://www.mediafire.com/file/bxsr7ics5k3p9gc/Student.pbix/file

v-yuaj-msft
Community Support
Community Support

Hi @deb_power123 ,

 

Do you want to exclude rows that contain less than the maximum selected value and rows that contain empty values, right?

This is even eaiser. You can modify the measure as follows.

filter_noblank_test = 

var x1=CALCULATE(MAX('Calendar'[Dates]),ALLSELECTED('Calendar'[Dates]))

return

IF(MAX('Students'[DateLeft])>x1,1,0)
Then you can repeat the same steps as I mentioned before.
Result:
 030802.gif

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thankyou Yuna for your reply.It is slighlty different, its my bad that i couldnt explain it well.

 

Let me give an example .

 

1.JPG

If you can see Mary has one blank record in Last attendance Date in the above table for 02.05.2011 so I want to get rid of that null value of date or exclude this null value of date when I select the date range in my date slicer as minimum date = 01.05.2011 and max date as 03.05.2011 so only three values should return and null values should be removed. 

 

Present visual shows something like this .

2.JPG

 

I want to get rid of the rows containing all those blank or null values for Last Attendance dates column..

Can we modify the above measure recommended by you to handle this scenario? Please suggest..

 

Regards

sameer

v-yuaj-msft
Community Support
Community Support

Hi @deb_power123 ,

 

There seems to be some errors in your description.

v-yuaj-msft_0-1615192644661.png

v-yuaj-msft_1-1615192745816.png

 

There are only 30 days in September and the relationship between "calendar"[Dates] and "Student"[LastAttendanceDate] should be 1:many.

Then you can do some steps as follows.

1. create a measure

filter_test = 

var x1=CALCULATE(MAX('Calendar'[Dates]),ALLSELECTED('Calendar'[Dates]))

return

IF(NOT(ISBLANK(MAX('Students'[DateLeft])))&&MAX('Students'[DateLeft])<x1,0,1)
2. drag it to the filter of the table visual and select "value is 1".
Result:
030801.gif

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thankyou Yuna for the response.Could you please let me know how can  I exlude all the rows having null values for "date left "which are falling under the minimum and maximum calendar selected date range?

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.