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

Dispay Value if any date falls within a filter range

Hi All,

 

Have a DAX logic problem I cant wrap my head around.

 

Scenario:

This week = 12/07 - 18/07

I need to filter the below table so that if any date for a Key falls within this week, that all rows, regardless of the date are displayed.

Rows 4, 5, and 9 are filtered out as no dates for those keys fall within the current week.

Rows 3 and 8 are included because another date for the same keys falls within the current week, even though the dates on those rows are outside the range.

FACT TABLE:

KeyDateRow
111-Jul1
117-Jul2
119-Jul3
211-Jul4
225-Jul5
313-Jul6
312-Jul7
330-Jul8
430-Jul9
515-Jul10
516-Jul

11

 

FILTERED RESULT:

KeyDateRow
111-Jul1
117-Jul2
119-Jul3
313-Jul6
312-Jul7
330-Jul8
515-Jul10
516-Jul11



I hope this is clear enough.

Thanks in advance,

Jordan

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

Hi, @JRB 

 

First, create a calendar table with a WeekNum column:

Calendar = CALENDAR(DATE(2021,1,1),DATE(2021,12,31))
weekNum = WEEKNUM([Date],2)

Slicer: "calendar"[weekNum]

 

The filter measure will be this:

_Result =
VAR _filter =
    SUMMARIZE (
        FILTER ( ALL ( 'Table' ), 'Table'[Key] = MAX ( 'Table'[Key] ) ),
        [Date]
    )
VAR _isIn =
    CALCULATETABLE (
        ALLSELECTED ( 'Calendar' ),
        TREATAS ( _filter, 'Calendar'[Date] )
    )
VAR _countIsIN =
    COUNTROWS ( _isIn )
VAR _if =
    IF ( COUNTROWS ( _isIn ) <> 0, 1, 0 )
RETURN
    _countIsIN

Finally, filter the items whose results are not empty in the filter pane.

 

Result:

vangzhengmsft_0-1626325175416.png

vangzhengmsft_1-1626325181310.png

Please refer to the attachment below for details

 

 

Hope this helps.

 

Best Regards,
Community Support Team _ Zeon Zheng
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

2 REPLIES 2
v-angzheng-msft
Community Support
Community Support

Hi, @JRB 

 

First, create a calendar table with a WeekNum column:

Calendar = CALENDAR(DATE(2021,1,1),DATE(2021,12,31))
weekNum = WEEKNUM([Date],2)

Slicer: "calendar"[weekNum]

 

The filter measure will be this:

_Result =
VAR _filter =
    SUMMARIZE (
        FILTER ( ALL ( 'Table' ), 'Table'[Key] = MAX ( 'Table'[Key] ) ),
        [Date]
    )
VAR _isIn =
    CALCULATETABLE (
        ALLSELECTED ( 'Calendar' ),
        TREATAS ( _filter, 'Calendar'[Date] )
    )
VAR _countIsIN =
    COUNTROWS ( _isIn )
VAR _if =
    IF ( COUNTROWS ( _isIn ) <> 0, 1, 0 )
RETURN
    _countIsIN

Finally, filter the items whose results are not empty in the filter pane.

 

Result:

vangzhengmsft_0-1626325175416.png

vangzhengmsft_1-1626325181310.png

Please refer to the attachment below for details

 

 

Hope this helps.

 

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

amitchandak
Super User
Super User

@JRB , Assuming slicer is coming from independent table

 


new measure =
VAR _min = MINX( allselected('Calendar') , 'Calendar'[Date] )
VAR _max = MAXX(allselected('Calendar') , 'Calendar'[Date] )
var _date1 = calculate(min(Table[Date]), filter(allselected(Table), Table[Key] =max(Table[Key])))
var _date2 = calculate(min(Table[Date]), filter(allselected(Table), Table[Key] =max(Table[Key])))
return
calculate(sum(Table[row]), filter(Table, (_date1 >=_min && _date1 <= _max) || (_date2 >=_min && _date2 <= _max)))

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.