Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

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.

 

 

1 ACCEPTED SOLUTION

@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] ) ) )
)

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

@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)

tamerj1
Super User
Super User

@Anonymous 

How does your visual look like?

Anonymous
Not applicable

I want a to display it on a card

@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] ) ) )
)
Anonymous
Not applicable

@tamerj1 perfect! 

Is it to much to ask the rational behind your code?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.