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
jwarne
New Member

Select Max and Min date for User in table

Hi Everyone,

 

I'm trying to work out how to build a query that will return the first and last dates of when a user was in a table. 

 

The data is formatted like this and I can't work out how to "select for" The values in the first row are indicitive of what I'd want to get as a result. 

 

 

DateUsernameFirstDateLastDate
28/02/2017 0:00accounts2/02/2017 0:001/03/2017 0:00
27/02/2017 0:00accounts  
26/02/2017 0:00accounts  
25/02/2017 0:00accounts  
24/02/2017 0:00accounts  
23/02/2017 0:00accounts  
22/02/2017 0:00accounts  
21/02/2017 0:00accounts  
20/02/2017 0:00accounts  
18/02/2017 0:00accounts  
19/02/2017 0:00accounts  
17/02/2017 0:00accounts  
16/02/2017 0:00accounts  
15/02/2017 0:00accounts  
14/02/2017 0:00accounts  
13/02/2017 0:00accounts  
12/02/2017 0:00accounts  
11/02/2017 0:00accounts  
10/02/2017 0:00accounts  
9/02/2017 0:00accounts  
8/02/2017 0:00accounts  
7/02/2017 0:00accounts  
2/02/2017 0:00accounts  
3/02/2017 0:00accounts  
4/02/2017 0:00accounts  
5/02/2017 0:00accounts  
6/02/2017 0:00accounts  
6/02/2017 0:00admin  
5/02/2017 0:00admin  
4/02/2017 0:00admin  
3/02/2017 0:00admin  
2/02/2017 0:00admin  
7/02/2017 0:00admin  
8/02/2017 0:00admin  
9/02/2017 0:00admin  
10/02/2017 0:00admin  
11/02/2017 0:00admin  
12/02/2017 0:00admin  
13/02/2017 0:00admin  
14/02/2017 0:00admin  
15/02/2017 0:00admin  
16/02/2017 0:00admin  
17/02/2017 0:00admin  
19/02/2017 0:00admin  
18/02/2017 0:00admin  
20/02/2017 0:00admin  
21/02/2017 0:00admin  
22/02/2017 0:00admin  
23/02/2017 0:00admin  
24/02/2017 0:00admin  
25/02/2017 0:00admin  
26/02/2017 0:00admin  
27/02/2017 0:00admin  
28/02/2017 0:00admin  
1/03/2017 0:00admin  
3/02/2017 0:00Test  
2/02/2017 0:00Test  
7/02/2017 0:00Test  
8/02/2017 0:00Test  
9/02/2017 0:00Test  
10/02/2017 0:00Test  
11/02/2017 0:00Test  
12/02/2017 0:00Test  
13/02/2017 0:00Test  
14/02/2017 0:00Test  
15/02/2017 0:00Test  
16/02/2017 0:00Test  
17/02/2017 0:00Test  
19/02/2017 0:00Test  
18/02/2017 0:00Test  
20/02/2017 0:00Test  
21/02/2017 0:00Test  
22/02/2017 0:00Test  
23/02/2017 0:00Test  
24/02/2017 0:00Test  
25/02/2017 0:00Test  
26/02/2017 0:00Test  
27/02/2017 0:00Test  
28/02/2017 0:00Test  
1/03/2017 0:00Test  

 

Anyone have any advice?

 

Cheers, 

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

Here's why I said the requirement is unclear - at first I thought @jwarne wants First and Last Date by Username

So I got the same result as @MarcelBeug

However when I compared to the result in the first row in the original post which I took to be the desired outcome

then it seems it is first and last date regardless of Username hence unclear?

BTW you can also achieve @MarcelBeug's result with DAX but instead of a new table you can add 2 Calculated Columns

 

SummarizeColumn - First & Last Date2.png

View solution in original post

4 REPLIES 4
rocky09
Solution Sage
Solution Sage

Try this

 

summary = SUMMARIZE(Table1,Table1[Username],"LastDate",MAX(Table1[Date]),"FirstDate",MIN(Table1[Date]))

data needs to be format before.

accounts12/2/20172/2/2017
admin12/2/20171/3/2017
Test12/2/20171/3/2017

 

 

Alternatively, you can use Group By in Power Query as illustrated in this video (dates in MM/DD/YYYY).

 

Not in the video: you might want to add an index column first so this can be used to get your original sort back at the end.

Specializing in Power Query Formula Language (M)
Sean
Community Champion
Community Champion

Here's why I said the requirement is unclear - at first I thought @jwarne wants First and Last Date by Username

So I got the same result as @MarcelBeug

However when I compared to the result in the first row in the original post which I took to be the desired outcome

then it seems it is first and last date regardless of Username hence unclear?

BTW you can also achieve @MarcelBeug's result with DAX but instead of a new table you can add 2 Calculated Columns

 

SummarizeColumn - First & Last Date2.png

Sean
Community Champion
Community Champion

Your requirement is unclear? Can you post desired outcome?

 

I was going to offer you this - but that's not what you show in the first row?

 

Summary Table =
SUMMARIZECOLUMNS (
    'Table'[Username],
    "FirstDate", FIRSTDATE ( 'Table'[Date] ),
    "LastDate", LASTDATE ( 'Table'[Date] )
)

SummarizeColumn - First & Last Date.png

EDIT: Just a clarification about the picture

I had to convert your Dates to US format so what you see as 3/1/2017 is March 1, 2017.

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.