Forum Discussion
Creating Calculated Column based on the ID, and the most recent datetime column in DAX
I have the following 1K ++ records table in my PBI report with Virtual Machine's IDs and Scan date-time info:
Table1 (this is a data snapshot, example)
I need to create [QryDate_Upd] - calculated column, which will do the following -
If there are the same VMIDs, same QryDates -> then it should select the most highest date-time value
otherwise it should just copy the values from the QryDate column
For example, for VMID = hh-3355, there are QryDate dates = 10/01/2020 and 10/15/2021. I need the calculated column to determine the highest date-time value for 10/01/2020, which is 8 50 PM
I expect the following outcome:
I have the following DAX code for this
QryDate_upd =
CALCULATE(
MAX(Table1[QryDate]),
ALLEXCEPT(Table1, Table1[VMID], Table1[QryDate].[Date])
)
But the problem is that my [QryDate] field related to a [Date] field in my Date calendar table
The code above only lets me use Table1[QryDate].[Date] field - only if I remove the Date tbl relation
Wondering, if there more efficient way to create this calculated column?
Hell-1934 , Better to have date column first
Date = Datevalue([QryDate])
Then have columns like
Maxx(filter( Table1, [VMID] = earlier([VMID]) && [Date] = earlier([Date]) ), [QryDate])
Power BI DAX- Earlier, I should have known Earlier: https://www.youtube.com/watch?v=cN8AO3_vmlY&t=17820s&list=PLPaNVDMhUXGYU97pdqwoaociLdwyDRn39&index=1
2 Replies
- amitchandak
Super User
Hell-1934 , Better to have date column first
Date = Datevalue([QryDate])
Then have columns like
Maxx(filter( Table1, [VMID] = earlier([VMID]) && [Date] = earlier([Date]) ), [QryDate])
Power BI DAX- Earlier, I should have known Earlier: https://www.youtube.com/watch?v=cN8AO3_vmlY&t=17820s&list=PLPaNVDMhUXGYU97pdqwoaociLdwyDRn39&index=1
- Hell-1934New Member
Thank you, amitchandak it worked
The code should be -Latest SCAN Date = MAXX( FILTER( Table1, Table1[VMID] = EARLIER(Table1[VMID]) && DATEVALUE(Table1[QryDate]) = DATEVALUE(EARLIER(Table1[QryDate])) ), Table1[QryDate] )