Forum Discussion
Direct Query compatible DAX calculation on time difference
Hi,
Need some help with this DAX formula.
Im using direct query and I have tried to some dax formula that was not compatible with Direct Query.
I need to calculate the minimum cycle time for each product between the PCBserialnumbers.
| Product | PcbSerialNumber | Finished Date |
| Vehicle | 5552822 | 2022-03-21 21:43 |
| Vehicle | 5705391 | 2022-03-21 19:56 |
| Vehicle | 5705392 | 2022-03-21 19:58 |
| Vehicle | 5706310 | 2022-03-21 20:00 |
| Vehicle | 5706311 | 2022-03-21 22:00 |
| Vehicle | 5728095 | 2022-03-21 21:41 |
| Vehicle | 5728110 | 2022-03-21 19:55 |
| Vehicle | 5728111 | 2022-03-21 19:59 |
| Textile | 5728117 | 2022-03-21 22:12 |
| Textile | 6794296 | 2022-03-21 19:36 |
| Textile | 6794297 | 2022-03-21 19:35 |
| Textile | 6975356 | 2022-03-21 21:38 |
| Textile | 6975401 | 2022-03-21 21:53 |
| Textile | 6975560 | 2022-03-21 19:47 |
| Textile | 6975561 | 2022-03-21 19:49 |
| Textile | 6976247 | 2022-03-21 21:00 |
| Textile | 6976248 | 2022-03-21 21:03 |
| Textile | 6976337 | 2022-03-21 20:44 |
| Textile | 6976338 | 2022-03-21 20:48 |
| Textile | 7222877 | 2022-03-21 21:21 |
Hi TcT85 ,
Please check if this is what you want:
DAX Date Previous1 = VAR CurDate_ = MAX ( PD_PcbProductionData[Finished Date] ) VAR CurProduct_ = MAX ( PD_PcbProductionData[Product] ) RETURN CALCULATE ( MAX ( PD_PcbProductionData[Finished Date] ), PD_PcbProductionData[Product] = CurProduct_, PD_PcbProductionData[Finished Date] < CurDate_, ALLSELECTED ( PD_PcbProductionData ) )EARLIER function is mostly used in the context of calculated columns. It is not supported in this scenario.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi TcT85 ,
Use MAX() / MIN() function like so:
Measure = DATEDIFF ( MAX ( PD_PcbProductionData[Finished Date] ), [DAX Date Previous1], SECOND )Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
7 Replies
- amitchandakSuper User
TcT85 , can you explain the calculation?
- TcT85Helper III
Hi,
I followed microsoft suggestion to first create this colum
DAX Date Previous1 =CALCULATE (MAX ( PD_PcbProductionData[SEL_LOD_LatestStartDateTime] ),ALLEXCEPT ( PD_PcbProductionData, PD_PcbProductionData[PcbSerialNumber] ),PD_PcbProductionData[SEL_LOD_LatestStartDateTime] < EARLIER ( 'PD_PcbProductionData'[SEL_LOD_LatestStartDateTime] ))But here it says Calculate is not allowed in a DAX expression for Direct query model.If previous column worked i would try to follow up with this secondary dax formula.Date Diff in Days =
IF (
ISBLANK ( 'View Name'[Date Previous] ),
1,
DATEDIFF (
'View Name'[Date Previous],
'View Name'[Date],
DAY
)
)But I would replace DAY with Second
Not sure if this would work though
- IceyCommunity Support
Hi TcT85 ,
Please check if this is what you want:
DAX Date Previous1 = VAR CurDate_ = MAX ( PD_PcbProductionData[Finished Date] ) VAR CurProduct_ = MAX ( PD_PcbProductionData[Product] ) RETURN CALCULATE ( MAX ( PD_PcbProductionData[Finished Date] ), PD_PcbProductionData[Product] = CurProduct_, PD_PcbProductionData[Finished Date] < CurDate_, ALLSELECTED ( PD_PcbProductionData ) )EARLIER function is mostly used in the context of calculated columns. It is not supported in this scenario.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.