Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Hell-1934
New Member

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)
Table1.jpg

 

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:
Table2.jpg

 

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?
 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
Hell-1934
New 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]
)

 

amitchandak
Super User
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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.