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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Terrassa
Helper I
Helper I

Get records between start and end date using a slicer

Hello,

I have a table with this structure:

NameStart dateEnd date
A01/02/202025/02/2021
B02/06/202001/01/2021
C01/05/2020 
D20/04/202031/12/2020

 

Date format is dd/mm/yyyy

 

I need to pick a date from a slicer, and based on that date I must retrieve all the records that were active on that date (picked date between start and end date, both included). Records with empty end date are still active.

 

Examples:

10/2/2020

I should get record: A

 

1/1/2021

I should get records: A, B, C

 

1/5/2020

I should get records: A, C, D

 

I don't know how to do this.

1 ACCEPTED SOLUTION
barritown
Super User
Super User

Hi @Terrassa,

 

Depending on how you want to list the final output, you may need one measure plus additional filter linked to this measures or two measures below. Check the attached PBIX file for more details.

 

filterMeasure = 
VAR startDate = MAX ( dataTbl[Start date] )
VAR endDate = MAX ( dataTbl[End date] )
VAR selectedDate = MAX ( calendarTbl[Date] )
VAR conditionOne = SWITCH ( TRUE(),
    ISBLANK ( startDate ), TRUE(),
    startDate <= selectedDate, TRUE(),
    FALSE() )
VAR conditionTwo = SWITCH ( TRUE(),
    ISBLANK ( endDate ), TRUE(),
    endDate >= selectedDate, TRUE(),
    FALSE() )
RETURN IF ( conditionOne && conditionTwo, 1, 0 )

 

barritown_0-1715890475049.png

listedNames = 
VAR _tbl = ADDCOLUMNS ( dataTbl, "flag", [filterMeasure] )
RETURN CONCATENATEX ( FILTER ( _tbl, [flag] = 1 ), [Name], ", " )

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

View solution in original post

1 REPLY 1
barritown
Super User
Super User

Hi @Terrassa,

 

Depending on how you want to list the final output, you may need one measure plus additional filter linked to this measures or two measures below. Check the attached PBIX file for more details.

 

filterMeasure = 
VAR startDate = MAX ( dataTbl[Start date] )
VAR endDate = MAX ( dataTbl[End date] )
VAR selectedDate = MAX ( calendarTbl[Date] )
VAR conditionOne = SWITCH ( TRUE(),
    ISBLANK ( startDate ), TRUE(),
    startDate <= selectedDate, TRUE(),
    FALSE() )
VAR conditionTwo = SWITCH ( TRUE(),
    ISBLANK ( endDate ), TRUE(),
    endDate >= selectedDate, TRUE(),
    FALSE() )
RETURN IF ( conditionOne && conditionTwo, 1, 0 )

 

barritown_0-1715890475049.png

listedNames = 
VAR _tbl = ADDCOLUMNS ( dataTbl, "flag", [filterMeasure] )
RETURN CONCATENATEX ( FILTER ( _tbl, [flag] = 1 ), [Name], ", " )

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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