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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
nr63bi
Helper I
Helper I

Select rows with Minimum date in DAX Table

Hello, 

 

I have a problem in Power BI

 

I use Power BI (not Query) and in table, i want to return only rows by the min date of the key. 

 

For example

 

A 2/01 Blue

A 3/01 Red

A 5/01 Blue

B 3/02 Blue

B 5/04 Red

 

I want : A 2/01 Blue

             B 3/02 Blue

 

I tried to use SUMMARIZE but it only returns the key and the min date, and note the other columns like the color in my example. 

 

How can i return the entire row that contains the min date per key ? 

4 REPLIES 4
Greg_Deckler
Super User
Super User

@nr63bi Maybe:

Table =
  VAR __Table = SUMMARIZE('Table', [ID], "__Date", MIN('Table'[Date]))
  VAR __IDs = SELECTCOLUMNS(__Table, "__ID", [ID])
  VAR __Dates = SELECTCOLUMNS(__Table, "__Date", [__Date])
  VAR __Result = FILTER('Table', [ID] IN __IDs && [Date] IN __Dates)
RETURN
  __Result

@ 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 hey thank you i like the idea but it don't work

 

it returns me 100 000 rows and i expect 19 521 

 

nr63bi_0-1684249677337.png

 

(the distinct) 

@nr63bi Try this:

Table =
  VAR __Table = SUMMARIZE('Table', [ID], "__Date", MIN('Table'[Date]))
  VAR __IDs = SELECTCOLUMNS(__Table, "__ID", [ID])
  VAR __Dates = SELECTCOLUMNS(__Table, "__Date", [__Date])
  VAR __Result = DISTINCT(FILTER('Table', [ID] IN __IDs && [Date] IN __Dates))
RETURN
  __Result

@ 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 

 

I try another solution inspired by your answer

 

I use _IdDate= ADDCOLUMNS(_Table,"ID&Date",CONCATENATE(ID,Date)
 
In the original table i add the column CONCATENE ID,Date
 
and i filter like FILTER('Table',CONCATENETAIDDATE in IDDate)
 
But i have the error "invalid number of arguments, function CONTAINSROWS must have value for each expression of the table"
 
But  don't use containsrows  

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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