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
amaan91
Helper I
Helper I

I am trying to get the last second date for a calculated column in a virtual table.

 
1 ACCEPTED SOLUTION

@amaan91 You have 3 choices. You can create your table and then use the lookup code in a calculated column for that table or you can adapt the code to use ADDCOLUMNS or you can simply extend your SUMMARIZE statement like this:

My Table = SUMMARIZE('Table', [column1], [column2], [column3], "__LastDate", MAX('Table'[the date column])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
amaan91
Helper I
Helper I

@Greg_Deckler  
tried your code its returning error not sure wt i am doing wrong 

amaan91_0-1710841081452.png

 

The 

 VAR __LastDate = MAXX( Table_1, Append1[StatusDateTime]

is retuning last date for Append1 table and not the Table_1 

@amaan91 You have 3 choices. You can create your table and then use the lookup code in a calculated column for that table or you can adapt the code to use ADDCOLUMNS or you can simply extend your SUMMARIZE statement like this:

My Table = SUMMARIZE('Table', [column1], [column2], [column3], "__LastDate", MAX('Table'[the date column])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@amaan91 Maybe:

Measure = 
  VAR __Table = "My virtual table goes here"
  VAR __LastDate = MAXX( __Table, [Date] )
  VAR __SecondToLastDate = MAXX( FILTER( __Table, [Date] <> __LastDate ), [Date] )
RETURN
  __SecondToLastDate



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler 

I am trying to get this within a virtual table 


ADDCOLUMNS(
SUMMARIZE( Append1 , Append1[CustomerName]  , Append1[Year] , Append1[Month No] ,  Append1[JobReference] , Append1[StatusDateTime] ,
 "Date" , LASTNONBLANK( Append1[StatusDateTime], 1) ,
" Accpted Rev" , [Accepted Sales.AG]  ,
"First Date" , CALCULATE( FIRSTNONBLANK(Append1[StatusDateTime] , 1 ) ,  ALLEXCEPT(Append1 , Append1[CustomerName])) ,
"Last Date" , CALCULATE(  LASTNONBLANK( Append1[StatusDateTime] , 1 ) ,  ALLEXCEPT(Append1 , Append1[CustomerName])) ,
//"Last Second" , CALCULATE( Max( TOPN( 2 , Append1 , Append1[StatusDateTime] , 0 ))),

"Period" ,  IF(   (Append1[StatusDateTime] - CALCULATE( FIRSTNONBLANK(Append1[StatusDateTime] , 1 ) ,  ALLEXCEPT(Append1 , Append1[CustomerName]))) / (365/12) <= 12 , 1 , 0  )  
 ) ,
 
 var Tab = SUMMARIZE( Append1 , Append1[CustomerName] ,  Append1[StatusDateTime])
 
  VAR __LastDate = MAXX( Tab , Append1[StatusDateTime]  )

  VAR __SecondToLastDate = MAXX( FILTER(  Tab  , [StatusDateTime] <> __LastDate ), [StatusDateTime] )
RETURN
  __SecondToLastDate

)
 
I am not able to refrence it




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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