Forum Discussion
Direct Query compatible DAX calculation on time difference
- 4 years ago
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.
TcT85 , can you explain the calculation?
Hi,
I followed microsoft suggestion to first create this colum
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
- Icey4 years agoCommunity 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.
- TcT854 years agoHelper III
Hi Icey,
Thanks for the DAX formula.
This is the key for me to calculate the cycle time.
When i use Datediff to get the cycle time number, it says that function calculate is not allowed for a new column. in direct query model.
- Icey4 years agoCommunity Support
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.