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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
user35131
Helper III
Helper III

How to group by latest date but within creating table process with multiple variables?

I would like to subset the largest date column from each group(id)

IDDate
14/10/2020
14/17/2020
14/29/2020
25/17/2020
212/17/2020

 

My out come should look like this

 

IDDate
14/29/2020
212/17/2020
 
Normally the way I would do this is using this line of Code
Date = CALCULATE(MAX(Table[date]),ALLEXCEPT(Table,Table[id]))
 
However I am doing this within a create table box with multiple variables. At a certain point its harder to reference the column names and I get stuck.
 

Var table2 =

 

DISTINCT(SELECTCOLUMNS( CALCULATETABLE('Table',

FILTER('Table’,NOT('Table’ [Col1]) IN {"Subset1","Subset2”

),

FILTER('Table,'Table[Col2] IN

{"Subset1","Subset2","Subset3",}

),

FILTER('Table,'Table'[Date]>=DATE(YEAR(MAX('Table'[Date]))-1,MONTH(MAX('Table'[ Date])),DAY(MAX('Table'[Date])))

))

,"Col1",'Table'[Col1],"Col2",'Table'[Date],"Col3", 'Table'[Col3]

))

 

var table3 =

 

SELECTCOLUMNS(table,"ID",[Col1],"Date",[Date])

 
Return table3
 
This returns the table shown above. However I want to select and filter by the max date for each id or if easier create a long column that pulls the largest date for each line based on group.
 
note that I'm trying to get the columns from table3 and not original table. How do i go about this? 
 
I tried doing this 
 
var table4 = 
 
SELECT
 
SELECTCOLUMNS(table3,"ID",[ID],"date",[date],"Max Date",CALCULATE(MAX([_date]),ALLEXCEPT(table3,[id])))
 
Also note disregard if it doesn't truly make sense. I've done my best to replicate the code to get it to what it is without showing the subset names of the data i'm using. 
 
 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@user35131 , You are suing date then it will not reduce the table

 

filter(SELECTCOLUMNS(table3,"ID",[ID],"date",[date],"Max Date",CALCULATE(MAX([_date]),ALLEXCEPT(table3,[id])))

[Date] =[Max Date])

 

 

or

 

Summarize(Table, Table[ID] , "Date" , Max(Table[Date]) )

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

3 REPLIES 3
user35131
Helper III
Helper III

The problem in both scripts is that it doesn't pick up on the column name within functions. I'm able to add ID and Date in select columns as a stand alone. Note where its bold i'm having trouble.

 

filter(SELECTCOLUMNS(table3,"ID",[ID],"date",[date],"Max Date",CALCULATE(MAX([_date]),ALLEXCEPT(table3,[id])))

 

Summarize(Table, Table[ID] , "Date" , Max(Table[Date]) )
 

I found that instead of Summarize(Table, Table[ID] , "Date" , Max(Table[Date]) ) working

 

that its better to do table 3 as the funneled table and then in the max add the original table not of a variable. I got the result i wanted. Thanky you. 

 

Summarize(Table3, Table3[ID] , "Date" , Max(Table[Date]) )

amitchandak
Super User
Super User

@user35131 , You are suing date then it will not reduce the table

 

filter(SELECTCOLUMNS(table3,"ID",[ID],"date",[date],"Max Date",CALCULATE(MAX([_date]),ALLEXCEPT(table3,[id])))

[Date] =[Max Date])

 

 

or

 

Summarize(Table, Table[ID] , "Date" , Max(Table[Date]) )

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.