Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Conditional Grouped SUM

Hello everyone,

 

I am having trouble to sum a column by ticket ID but the ticket_ID must follow a rule. 

 

Ticket_idProductProduct_TypeAmount
1A010
1B15
1C010
2A010
2C010
3B15
4B15
4C010

 

I want to sum the total sales, of tickets that have at least a Product_type = 1.

 

In the example above, the result should sum the total amount of tickets 1, 3 and 4 (a total of 45) because they have at least one product of type 1.

 

 

  • tamerj1's avatar
    tamerj1
    4 years ago

    Anonymous 

    Try

    Product	Total Amount =
    SUMX (
        VALUES ( Data[Ticket_id] ),
        VAR Check =
            CALCULATE ( COUNTROWS ( CALCULATETABLE ( Data, Data[Product_Type] = 1 ) ) )
        RETURN
            IF ( NOT ISBLANK ( Check ), CALCULATE ( SUM ( Data[Amount] ) ) )
    )

5 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      I want a to display it on a card

      • tamerj1's avatar
        tamerj1
        Community Champion

        Anonymous 

        Try

        Product	Total Amount =
        SUMX (
            VALUES ( Data[Ticket_id] ),
            VAR Check =
                CALCULATE ( COUNTROWS ( CALCULATETABLE ( Data, Data[Product_Type] = 1 ) ) )
            RETURN
                IF ( NOT ISBLANK ( Check ), CALCULATE ( SUM ( Data[Amount] ) ) )
        )
  • tamerj1's avatar
    tamerj1
    Community Champion

    Anonymous 

    The iteration ove the values of ID's will provide access to aggregation over ID level as will as to check conditions row by row (aggregated at ID level)