Forum Discussion

jwarne's avatar
jwarne
New Member
9 years ago
Solved

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, 

  • Sean's avatar
    Sean
    9 years ago

    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

     

4 Replies

  • Sean's avatar
    Sean
    Icon for Community Champion rankCommunity 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] )
    )

    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.

  • rocky09's avatar
    rocky09
    Icon for Solution Sage rankSolution 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

     

     

    • MarcelBeug's avatar
      MarcelBeug
      Icon for Community Champion rankCommunity Champion

      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.

      • Sean's avatar
        Sean
        Icon for Community Champion rankCommunity 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