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
Enila123
Regular Visitor

Power BI dynamic filter date between

Hey everyone,

 

I've got this table:

 

area_ID        start_date         end_date       size

    1              01/01/16          10/01/16       500

    1              11/01/16          30/05/16       510

    1              01/06/16          NULL             520   (NULL means until today)

    2              05/01/16          20/01/16       380

and so on

 

On my Dashboard I need a slicer for the area_ID and a slicer for date. If I select area_ID = 1 and date = 03/01/16, I only want to see the first row. My problem is that I don't know how to filter the date correctly because the table only shows the start and end date. I created a new Table Calendar with all dates but I don't know how to combine that dynamically.

If anyone could help me how to solve that problem, I would be very very thankful! 🙂

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey,

 

here you will find a little pbix file.

 

The solution is based upon the following

  • The separate calendar table is not related to the fact table containing "Date Start" and "Date End"

I created this measure in the fact table

Check Date Selection = 
var DateSelected = MINX(VALUES('Calendar'[Date]),'Calendar'[Date])
return
CALCULATE(
	SUMX(
		'Table1'
		,
        var DateStart = 'Table1'[DateStart]
        var DateEnd = IF(ISBLANK('Table1'[DateEnd]),TODAY(), 'Table1'[DateEnd])
        return
        IF(AND(DateStart <= DateSelected,
            DateEnd >= DateSelected)
			,1
			,BLANK()
		)
	)		
)

Basically this measure iterates through all the rows of the facttable and checks if the selected date from the slicer is between DateStart and DateEnd, if so the row is marked with the value 1 (the number is meaningless further on, it is just necessary, that it is not BLANK().

 

Be aware that this measure is used in Visual Level filters of the the table visual, here i use "Check Date Selection" is not blank.

 

Hopefully this is what you are looking for

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

2 REPLIES 2
TomMartens
Super User
Super User

Hey,

 

here you will find a little pbix file.

 

The solution is based upon the following

  • The separate calendar table is not related to the fact table containing "Date Start" and "Date End"

I created this measure in the fact table

Check Date Selection = 
var DateSelected = MINX(VALUES('Calendar'[Date]),'Calendar'[Date])
return
CALCULATE(
	SUMX(
		'Table1'
		,
        var DateStart = 'Table1'[DateStart]
        var DateEnd = IF(ISBLANK('Table1'[DateEnd]),TODAY(), 'Table1'[DateEnd])
        return
        IF(AND(DateStart <= DateSelected,
            DateEnd >= DateSelected)
			,1
			,BLANK()
		)
	)		
)

Basically this measure iterates through all the rows of the facttable and checks if the selected date from the slicer is between DateStart and DateEnd, if so the row is marked with the value 1 (the number is meaningless further on, it is just necessary, that it is not BLANK().

 

Be aware that this measure is used in Visual Level filters of the the table visual, here i use "Check Date Selection" is not blank.

 

Hopefully this is what you are looking for

 

Regards

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

That's great, I'm very happy!

Thank you very very much, you helped me a lot 🙂

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.