Forum Discussion
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)
| ID | Date |
| 1 | 4/10/2020 |
| 1 | 4/17/2020 |
| 1 | 4/29/2020 |
| 2 | 5/17/2020 |
| 2 | 12/17/2020 |
My out come should look like this
| ID | Date |
| 1 | 4/29/2020 |
| 2 | 12/17/2020 |
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])
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]) )
3 Replies
- amitchandak
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]) )
- user35131
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]) )- user35131
Helper III
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]) )