cancel
Showing results for 
Search instead for 
Did you mean: 
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]) )

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]) )

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors