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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
amaan91
Frequent Visitor

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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
amaan91
Frequent Visitor

@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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@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!:
The Definitive Guide to Power Query (M)

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Top Kudoed Authors