Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Sum of cost filtering minimum date (DAX)

Dear Team,

I need help to return the following,

 

For every Project Number in the table ,I want to calculate the sum of ‘Cost’ that has the minimum ‘Date’ present for that project number and a ‘Status’= L .

 

Project Number            Status             Date              Cost

        1                               L                12/4/2020        10

        1                               L                12/4/2020        10

        1                               L                12/18/2020        5

        1                               N                1/14/2020         8

 

I need to return, cost = 20 for Project Number 1 having a date 12/4/2020 &Status 'L'. Kindly suggest

 

 

4 Replies

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

    Hi Anonymous 

    1. Place Project Number in a table visual

    2. Place this measure in the visual 

    Measure =
    CALCULATE (
        VAR lastDate_ =
            MIN ( Table1[Date] )
        RETURN
            CALCULATE ( SUM ( Table1[Cost] ), Table1[Date] = lastDate_ ),
        Table1[Status] = "L"
    )

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers 

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello AIB,

       

      Thank you so much for your quick response. I did use the measure suggested and the table view returns no value. The project number is the unique key that drives Cost, Status and Date. Do we need to incorporate that in the query as well ?

       Thanks in advance!

       

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

        Anonymous 

        It's working on my side. See it all at work in the attached file.

        You can also select the "L" on a slicer rather than having it hardcoded in the measure

        Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

        Contact me privately for support with any larger-scale BI needs, tutoring, etc.

        Cheers 

         

  • Thanks for helping me solve my long time problem.  The solution contained in this thread gave me a good clue to solve my own challenging DAX problem!

     

    Thanks!