Forum Discussion

nirvana_moksh's avatar
nirvana_moksh
Impactful Individual
8 years ago
Solved

DAX or M Query

Hello All,

 

So there is this table I am importing along with 30 others for one of my reports.

 

This table consists of ID, Description Insert Date and Created By.

 

What I am trying to achieve is for this table to look through every occurrence  of the 'ID' value and ONLY filter the Latest/MAX value based on its 'Date'. So based on the below table for example for 'ID' number 12 there are 3 entries and in the end I want it to filter to the row of 'Insert Date' --> 5/15/2018 18:25.

 

 

ID                           Description                                                               Insert Date                                         Created By

12test 1231115/10/2018 13:42user 1
71215/11/2018 13:42user 1
121215/12/2018 14:12user 2
715/12/2018 14:13user 3
7test5/14/2018 14:52user 4
12this is the latest5/15/2018 18:25user 2
7878Test comment5/15/2018 18:58user 1
787test 15/16/2018 19:00user 2
7878test 15/15/2018 20:42user 2
989test 15/15/2018 21:02user 2
434test comment 25/18/2018 22:00user 2

 

 

I have tried options like:

  • Indexing
  • Trying to play with List.Max, List.Last
  • Attempting to add custom column containing values which indicate which row is the latest one
  • CaculcateTable(NaturalLeftOuterJoin) - Trying to use a filter for MAX(InsertDate) but that did not work

 

Any help or guidance would be really helpful

  • Hi nirvana_moksh

     

    You could try the following calculated table.  I have attached a PBIX file for you to test with.

     

    Table = 
    VAR myFilter = 
        SELECTCOLUMNS(
            SUMMARIZE(
                'Table1',
                [ID],"Latest Date",
                MAX('Table1'[Insert Date])
                ),
                "My ID",[ID],
                "Latest Date",[Latest Date]
                )
    RETURN FILTER(GENERATE(myFilter,'Table1'),[Latest Date]='Table1'[Insert Date] && [My ID] = [ID])

6 Replies

  • Phil_Seamark's avatar
    Phil_Seamark
    Microsoft Employee

    Hi nirvana_moksh

     

    You could try the following calculated table.  I have attached a PBIX file for you to test with.

     

    Table = 
    VAR myFilter = 
        SELECTCOLUMNS(
            SUMMARIZE(
                'Table1',
                [ID],"Latest Date",
                MAX('Table1'[Insert Date])
                ),
                "My ID",[ID],
                "Latest Date",[Latest Date]
                )
    RETURN FILTER(GENERATE(myFilter,'Table1'),[Latest Date]='Table1'[Insert Date] && [My ID] = [ID])

    • nirvana_moksh's avatar
      nirvana_moksh
      Impactful Individual
      Hey Phil,

      I am going to try this now, will this have a performance impact compared to a solution in M (if possible even) for the same problem ?