Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

SUM by category

Hello, I have a table and i want to create a mesure to calculate sum by each Cat, if i have the same Esp for each Cat and 2 dates i have to take only the mount of the lastdate Cat Esp Mount ...
  • tamerj1's avatar
    4 years ago

    Hi Anonymous 
    Here is the sample file with the solution https://www.dropbox.com/t/GTSytgeJpOM8WoQO
    One way to that is by starting with a calculated column that retrieves the last date as per your requirement.

    Last Date = 
    VAR CurrentCatEspTable =
        FILTER (
            Data,
            Data[Cat] = EARLIER ( Data[Cat] )
                && Data[Esp] = EARLIER ( Data[Esp] )
        )
    VAR Result =
        MAXX ( CurrentCatEspTable, Data[Date] )
    RETURN
        Result

    Then we can create our measure

    CatSUM = 
    CALCULATE ( 
        SUM ( Data[Mount] ),
        REMOVEFILTERS(),
        VALUES ( Data[Cat] ),
        FILTER ( 
            ALL ( Data ),
            Data[Date] = Data[Last Date]
        )       
    )

    The report looks like this

    Please let me know if this answers your query. Have a great day!