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.
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
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.
- TcT854 years agoHelper III
Yes, it works!!! Thanks Icey!
I added ABS to remove the minus value, not sure if this is the best solution.
Dax Measure = VAR Datedifferent= DATEDIFF ( MAX( PD_PcbProductionData[SEL_LOD_LatestEndDateTime] ), [DAX Date Previous2], SECOND ) Return ABS(Datedifferent)One more question.
How can i Sum all the measure values?
Dax Total Measure = CALCULATE(PD_PcbProductionData[Dax Measure])I tried to sum the measure values, but it doesnt calculate correct.
For some reason it only takes the latest value that is 556 at the image below.