Forum Discussion
Cross date time calculation
- Anonymous1 year ago
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) )Best Regards,
Gao
Community Support TeamIf 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
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)
)
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