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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
busmansholiday
Regular Visitor

Dax and date ranges

I have reviewed Solved: Lookup value within date range - Microsoft Power BI Community and other related posts of matching a date in one table to a date range in a second table.  However, these examples seem to assume that there is another categorical variable that I can use for the initial inner-join. My situation is different.

 

I have a list of dates:

2019-01-01

2020-01-01

2021-01-01

2022-01-01

 

and I have a list of intervals

start             stop            Categorical_Value

2019-01-01 2019-12-31 A

2019-12-31 2020-01-02 B

2019-12-31 2023-01-01 C

2020-01-02 2021-12-30 D

 

For each date (first list), I want to know which intervals overlap with that list, so for 2019-01-01 I would like a record of  the date and null values for start, stop and categorical_value.

Date   start             stop                     categorical value

2019-01-01 2019-12-31 2020-01-02 B

2020-01-01 2019-12-31 2023-01-01 C

 

Appropriate DAX for ths sort of join/lookup completely escapes me.


R

 

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

Hi, @busmansholiday 

Is this you expected result?

10.png

If so, you may need to join the two tables before filtering the data, because it is currently difficult to expand the rows by measure.  'lookupvalue'  also does not apply to row data expansion.

Sample:

 

 

New Table =
VAR tab =
    CROSSJOIN ( List, 'Table' )
VAR tab2 =
    FILTER ( tab, List[Date] > 'Table'[start] && List[Date] < 'Table'[stop] )
RETURN
    tab2

 

 

Best Regards,
Community Support Team _ Eason

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @busmansholiday 

Is this you expected result?

10.png

If so, you may need to join the two tables before filtering the data, because it is currently difficult to expand the rows by measure.  'lookupvalue'  also does not apply to row data expansion.

Sample:

 

 

New Table =
VAR tab =
    CROSSJOIN ( List, 'Table' )
VAR tab2 =
    FILTER ( tab, List[Date] > 'Table'[start] && List[Date] < 'Table'[stop] )
RETURN
    tab2

 

 

Best Regards,
Community Support Team _ Eason

amitchandak
Super User
Super User

@busmansholiday , assume the first date is an independent table

 

then you create a measure like this

new measure =

var _max = maxx(allselected(Date1),Date1[Date])

return

countrows(filter(Table2, Table2[Start Date] <= _max && Table2[End Date] >= _max ))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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