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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Date range in Direct Query mode

Hey guys, 

 

I have two dates in two different tables and I need to get days between those two dates. Datediff function does not work, also it is not possible to create a column, because they are in different tables, the only way I think of is through creating measures for those dates and use measure calculation, but I am not sure what function needs to be used.

 

Do you guys have better ideas?

 

I am using direct query mode btw 🙂 

 

Thanks, 

Sona

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

Hi @Anonymous ,

You can create one measure as below,  please find full details in my sample PBIX file.

1. Get the value of the date columns in that two tables separately

2. Calculate the number of days between these two dates

 getdaterange.JPG

 

 

GetDateRange =

VAR a =

    MAX ( '001_t1'[ID] )VAR sdate =

    CALCULATE ( MAX ( '001_t1'[Start date] ), '001_t1'[ID] = a )

VAR edate =

    CALCULATE (

        MAX ( '001_t2'[End Date] ),

        FILTER ( '001_t2', '001_t2'[PID] = a )

    )

 

VAR Ddiff =

    DATEDIFF ( sdate, edate, DAY )

RETURN

Ddiff

 

If the above formula is not applicable in your scenario, please provide me the related table structure and sample data.

 

Best Regards

Rena

Community Support Team _ Rena
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

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can create one measure as below,  please find full details in my sample PBIX file.

1. Get the value of the date columns in that two tables separately

2. Calculate the number of days between these two dates

 getdaterange.JPG

 

 

GetDateRange =

VAR a =

    MAX ( '001_t1'[ID] )VAR sdate =

    CALCULATE ( MAX ( '001_t1'[Start date] ), '001_t1'[ID] = a )

VAR edate =

    CALCULATE (

        MAX ( '001_t2'[End Date] ),

        FILTER ( '001_t2', '001_t2'[PID] = a )

    )

 

VAR Ddiff =

    DATEDIFF ( sdate, edate, DAY )

RETURN

Ddiff

 

If the above formula is not applicable in your scenario, please provide me the related table structure and sample data.

 

Best Regards

Rena

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

Hi,
I have the same query but instead of the count of days, I want to list all the dates between two dates(if exist). 

Eg.: 

Start Date = Feb,5,2022         End Date = Feb 8,2022

Output : Feb 5,2022

               Feb 6,2022 

               Feb 7,2022

               Feb 8,2022

 

amitchandak
Super User
Super User

@Anonymous 

Few days back I created this pbix, the 4 ways you can take datediff between two tables. I am not using a direct query, so not sure the solution will work. But solutions 3 and 4 use measure approach so you can try that. (way 3, way 4)

 

https://www.dropbox.com/s/bs6m71k27gc76vc/datediff.pbix?dl=0Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

 

 

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
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!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.