Forum Discussion

jrobertosm's avatar
jrobertosm
Frequent Visitor
5 years ago
Solved

Calculate the last value per group

Hi team,

I need help to return the value of the last item (Doc), group by Contratc.
I created an index column. But I am not able to calculate this last value.

The solution can be in DAX or M language.

 

Base:

ClientContractDocDate_DocValue_DocIndex
Miguel Santos120630D74589601/01/20201501
Miguel Santos120630D54218501/01/20211802
Ana Matos115312D96352115/05/2019801
Ana Matos115312D85295115/05/2020952
Rute Cardoso117689D75214510/02/2019601
Rute Cardoso117689D89635810/08/2019702
Rute Cardoso117689D96574510/02/2020653
Rute Cardoso117689D98732110/08/2020554
Alice Maria174541D55639515/06/2019301
Alice Maria174541D45874115/06/2020352
Alice Maria174541D63285615/06/2021403
Alice Maria256357D95896820/04/20191201
Alice Maria256357D14578920/04/20201252


Final result:

ClientContractDocDate_DocLast_Value_Doc
Miguel Santos120630D54218501/01/2021180
Ana Matos115312D85295115/05/202095
Rute Cardoso117689D98732110/08/202055
Alice Maria174541D63285615/06/202140
Alice Maria256357D14578920/04/2020125

 

Grateful for the help.

  • You can use following formule

     

    LastAvailableValue =
    var last_date = MAX('Table'[Date_Doc])
    RETURN
    CALCULATE(SUM('Table'[Value_Doc]),'Table'[Date_Doc] = last_date)
     
    Thanks,
    Sayali
     
    If this post helps, then please consider Accept it as the solution to help others find it more quickly.

2 Replies

  • You can use following formule

     

    LastAvailableValue =
    var last_date = MAX('Table'[Date_Doc])
    RETURN
    CALCULATE(SUM('Table'[Value_Doc]),'Table'[Date_Doc] = last_date)
     
    Thanks,
    Sayali
     
    If this post helps, then please consider Accept it as the solution to help others find it more quickly.