Forum Discussion

rennda's avatar
rennda
Frequent Visitor
7 years ago
Solved

Reference last row values filtered by multiple criteria

Dear Power BI community: I would really appreciate if you could help me out with my following problem. I would like to expand my table with the colums "Last Call" and "Last Employee" by a reference to the last row (matching MachineNo)

 

I try to fix my problem meanwhile for over two weeks and there ist actually no way to find a solution for me. So please help :)

 

CALL_IDMachineNoModellCall_DateLast CallEmployeeLast Employee
2908330408427KYOC TA 4551CI12.12.2018 16:27 KM 
2923350408427KYOC TA 4551CI04.01.2019 10:4612.12.2018 16:27KMKM
2925603408427KYOC TA 4551CI09.01.2019 10:2404.01.2019 10:46BTKM
2934951426616SHAR MXM90423.01.2019 16:07 SD 
2956653426616SHAR MXM90427.02.2019 10:4923.01.2019 16:07DSSD
2965052426616SHAR MXM90414.03.2019 14:4127.02.2019 10:49BPDS
2971818408427KYOC TA 4551CI26.03.2019 10:2109.01.2019 10:24BTBT
2972146426616SHAR MXM90426.03.2019 14:5514.03.2019 14:41WHBP
2989954426616SHAR MXM90405.04.2019 11:2926.03.2019 14:55WHWH
3005277426616SHAR MXM90407.05.2019 11:5105.04.2019 11:29SDWH
  • Hi rennda ,

    I created a sample to get the last row values. And you can check if it is what you want.

    Last call date = CALCULATE(MAX('Table'[Call_Date]),FILTER(ALLEXCEPT('Table','Table'[MachineNo]),'Table'[Call_Date] <= EARLIER('Table'[Call_Date])-1))
    Group rank = RANKX(FILTER('Table','Table'[MachineNo]=EARLIER('Table'[MachineNo])),'Table'[Call_Date],,ASC,Dense)
    Last Employee = CALCULATE(MAX('Table'[Employee]),FILTER('Table', 'Table'[MachineNo] = EARLIER('Table'[MachineNo]) &&'Table'[Group rank] = EARLIER('Table'[Group rank])-1))
    Last call date2 = CALCULATE(MAX('Table'[Call_Date]),FILTER('Table', 'Table'[MachineNo] = EARLIER('Table'[MachineNo]) &&'Table'[Group rank] = EARLIER('Table'[Group rank])-1))

    I attached my sample that you can download.

     

    Best Regards,

    Xue Ding

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Cmcmahan's avatar
    Cmcmahan
    Icon for Resident Rockstar rankResident Rockstar

    I've got bad news and good news for you.  The good news is that this IS doable within DAX.  The bad news is that it is not efficient and if you have a large data set will run incredibly slowly.

    You can read about somebody who had a similar problem here.  Be sure to read through all the replies first, because there was a lot of iteration on different methods for performance for that question.  Give it a try, and if you have questions about how to implement the solution for your dataset, feel free to ask follow up questions.

    • rennda's avatar
      rennda
      Frequent Visitor

      Hey Cmcmahan ,

       

      thanks for your reply. I tried it to read the link you have posted, but it seems to be to much information to me as a Power BI Rookie :)

       

      Is it possible to get the Name from the EMPLOYEE from the last TicketNo by the EARLIER function?  

      • v-xuding-msft's avatar
        v-xuding-msft
        Icon for Community Support rankCommunity Support

        Hi rennda ,

        I created a sample to get the last row values. And you can check if it is what you want.

        Last call date = CALCULATE(MAX('Table'[Call_Date]),FILTER(ALLEXCEPT('Table','Table'[MachineNo]),'Table'[Call_Date] <= EARLIER('Table'[Call_Date])-1))
        Group rank = RANKX(FILTER('Table','Table'[MachineNo]=EARLIER('Table'[MachineNo])),'Table'[Call_Date],,ASC,Dense)
        Last Employee = CALCULATE(MAX('Table'[Employee]),FILTER('Table', 'Table'[MachineNo] = EARLIER('Table'[MachineNo]) &&'Table'[Group rank] = EARLIER('Table'[Group rank])-1))
        Last call date2 = CALCULATE(MAX('Table'[Call_Date]),FILTER('Table', 'Table'[MachineNo] = EARLIER('Table'[MachineNo]) &&'Table'[Group rank] = EARLIER('Table'[Group rank])-1))

        I attached my sample that you can download.

         

        Best Regards,

        Xue Ding

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.