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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
magnus_b
Advocate II
Advocate II

Get totalt order revenue for orders containing a specific product

Hi!

 

I have tried searching for solutions, but couldn't find one that worked for my specifc use case.

I have a table like this:

 

orderidorderlineidproductnameamount
98711Product A92
98712Product X25
15361Product B150
15362Product A97
71521Product X82
71522Product X51
61281Product A41
61282Product B25


I then want to create the following measures:

1. Total order revenue for all orders containing Product X - expected result is 92+25+82+51 = 250
2. Number of orders containing Product X - expected result is 2

3. Total order revenue for all orders except orders containing Product X - expected result is 150+97+41+25 = 313
4. Number of orders except orders containing Product X - expected result is 2

I appreciate any help!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

[Total] = SUM( T[Amount] )

[# Orders] = DISTINCTCOUNT( T[Order ID] )

// 1
[Total X] =
var OrdersWithX =
    calculatetable(
        distinct( T[Order ID] ),
        keepfilters (
            T[Product] = "Product X"
        )
    )
return
calculate(
    [Total],
    OrdersWithX
)

// 2
[# Orders X] =
CALCULATE(
    [# Orders],
    KEEPFILTERS(
        T[Product Name] = "Product X"
    )    
)

// 3
[Total ~X] = [Total] - [Total X]

// 4
[# Orders ~X] = [# Orders] - [# Orders X]

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

 

[Total] = SUM( T[Amount] )

[# Orders] = DISTINCTCOUNT( T[Order ID] )

// 1
[Total X] =
var OrdersWithX =
    calculatetable(
        distinct( T[Order ID] ),
        keepfilters (
            T[Product] = "Product X"
        )
    )
return
calculate(
    [Total],
    OrdersWithX
)

// 2
[# Orders X] =
CALCULATE(
    [# Orders],
    KEEPFILTERS(
        T[Product Name] = "Product X"
    )    
)

// 3
[Total ~X] = [Total] - [Total X]

// 4
[# Orders ~X] = [# Orders] - [# Orders X]

 

That worked like a charm! Thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors