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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
TaroGulati
Helper III
Helper III

Cross date time calculation

Hi all, 

 

I am stuck with the following scenario:

TaroGulati_1-1738760736476.png

I need to calculate time difference between (from table 1 minimum start date with category = B & type = X) and (from table 2 minimum date with category = C) so the answer will be 23 hours. Out of these 23 hours i have to check if all these 23 hours are covered in start and end date from table 1 with category = A and type = X for each ID. So in this case 22 hours out of 23 are covered so result is 22 hours. I am able to calculate the time 23 hours which is first part but not able check the scope in table 1. 

Here is link of PBIx: Sample.pbix

 

thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @TaroGulati ,

 

Please try:

# Measure = 
VAR __start_datetime =
    CALCULATE (
        MIN ( 'Table1'[START] ),
        'Table1'[Category] = "B"
            && 'Table1'[Type] = "X"
    )
VAR __end_datetime =
    CALCULATE ( MIN ( 'Table2'[Date] ), 'Table2'[Category] = "C" )
RETURN
SUMX(
FILTER(
    ADDCOLUMNS (
        FILTER ( 'Table1', 'Table1'[Category] = "A" && 'Table1'[Type] = "X" ),
        "@start_datetime", __start_datetime,
        "@end_datetime", __end_datetime
    ),
    'Table1'[END]>=[@start_datetime] && 'Table1'[START]<=[@end_datetime]
),
VAR __overlap_start = MAX('Table1'[START],[@start_datetime])
VAR __overlap_end = MIN('Table1'[END],[@end_datetime])
RETURN
    DATEDIFF(__overlap_start,__overlap_end,HOUR)
)

vcgaomsft_0-1738810441884.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @TaroGulati ,

 

Please try:

# Measure = 
VAR __start_datetime =
    CALCULATE (
        MIN ( 'Table1'[START] ),
        'Table1'[Category] = "B"
            && 'Table1'[Type] = "X"
    )
VAR __end_datetime =
    CALCULATE ( MIN ( 'Table2'[Date] ), 'Table2'[Category] = "C" )
RETURN
SUMX(
FILTER(
    ADDCOLUMNS (
        FILTER ( 'Table1', 'Table1'[Category] = "A" && 'Table1'[Type] = "X" ),
        "@start_datetime", __start_datetime,
        "@end_datetime", __end_datetime
    ),
    'Table1'[END]>=[@start_datetime] && 'Table1'[START]<=[@end_datetime]
),
VAR __overlap_start = MAX('Table1'[START],[@start_datetime])
VAR __overlap_end = MIN('Table1'[END],[@end_datetime])
RETURN
    DATEDIFF(__overlap_start,__overlap_end,HOUR)
)

vcgaomsft_0-1738810441884.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

TaroGulati
Helper III
Helper III

hi, sorry didn't understand your answer. 

Please provide better sample data.

lbendlin
Super User
Super User

Can I interest you in a graphical solution?

 

lbendlin_0-1738773557553.png

 

Your sample data row 4 (3) is a non-event.

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors