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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
MattAtBP
Frequent Visitor

Formula help with Summarize, filter, max date...

Hi all,

 

I'm trying to create a new table that shows the cost of the most recent purchase of 'Product 1', per customer. I've tried a formula using summarize with filter and max date but just not quite getting there. Below is some sample data and the desired result. 

 

Thanks for looking...

Dax query.png

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

 Picture1.png

 

New Table =
ADDCOLUMNS (
TREATAS (
GROUPBY (
FILTER ( Data, Data[product] = 1 ),
Customers[customer],
Products[product],
"@datemax", MAXX ( CURRENTGROUP (), Data[date] )
),
Data[customer],
Data[product],
Data[date]
),
"@cost", CALCULATE ( SUM ( Data[cost] ) )
)

 

 

Link to the PBIX file 


 

    Microsoft MVP
 

 

   


      If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

 Picture1.png

 

New Table =
ADDCOLUMNS (
TREATAS (
GROUPBY (
FILTER ( Data, Data[product] = 1 ),
Customers[customer],
Products[product],
"@datemax", MAXX ( CURRENTGROUP (), Data[date] )
),
Data[customer],
Data[product],
Data[date]
),
"@cost", CALCULATE ( SUM ( Data[cost] ) )
)

 

 

Link to the PBIX file 


 

    Microsoft MVP
 

 

   


      If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


Many thanks, worked perfectly!

Anonymous
Not applicable

Another way of calculation:

[Your table] = // calulated table
CALCULATETABLE(

	var Filter_ = 
		ADDCOLUMNS(
			DISTINCT( T[Customer] ),
			"Date", CALCULATE( MAX( T[Date] ) )
		)
	var Result =
		CALCULATETABLE(
			T,
			TREATAS(
				Filter_,
				T[Customer],
				T[Date]
			)
		)
	return
		Result,
		
	T[Product] = "product 1"
)

Thanks Daxer for taking the time to help, works perfectly.

Anonymous
Not applicable

[Your table] = // calulated table
CALCULATETABLE(
	GENERATE(
		SUMMARIZE(
			T,
			T[Customer],
			T[Product],
		),
		SELECTCOLUMNS(
			CALCULATETABLE(
				TOPN(1,
					T,
					T[Date],
					DESC
				)
			),
			"Date", T[Date],
			"Cost", T[Cost]
		)
	),
	T[Product] = "product 1"
)

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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