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
xhead
Helper II
Helper II

Measure with SUMMARIZE

 

I have a table with Sales data at the item level. The table has an OrderID column that contains the order number of the item so many items share the same OrderID. Also, an order can have items added and dropped from it over time.

 

I need to have a calculated measure for the number of orders (distinct OrderID) that occured within a time period.

 

I have a column, OrderCount, that contains 1 for the rows that represent a new order, a 0 for the rows that represent an order change, and -1 for the rows that represent a cancelled order.

 

If I sum up the OrderCount column over time, for a specific OrderID, I will arrive at a number that is either positive, negative, or zero. A positive sum indicates 1 new order, a negative sum indicates 1 cancelled order, and a 0 indicates no new order or cancelled order. It doesn't really matter the size of the positive or negative number.

 

This is what I thought I could do:

 

 

OrderCount =
CALCULATE (
    SUM ( [WrittenOrders] ),
    SUMMARIZE (
        'Sales',
        'Sales'[OrderID],
        "WrittenOrders", IF (
            SUM ( 'Sales'[OrderCount] ) > 0,
            1,
            IF ( SUM ( 'Sales'[OrderCount] ) < 0, -1, 0 )
        )
    )
)

I realize now that columns in the inner CALCULATETABLE function (the one I created called "WrittenOrders") aren't exposed to the outside CALCULATE context, so the SUM([WrittenOrders]) fails.

 

How do I write this to do what I intend to do? I think I have my inner SUMMARIZE code written correctly to give me the sum by OrderID.

 

Mike

 

 

 

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@xhead

 

Hi Mike:

 

Use this and let me know if solve your issue

 

OrderTotal =
SUMX (
    SUMMARIZE (
        Table1,
        Table1[OrderID],
        "ORDERCOUNT", IF (
            SUM ( Table1[OrderCount] ) > 0,
            1,
            IF ( SUM ( Table1[OrderCount] ) < 0, -1, 0 )
        )
    ),
    [ORDERCOUNT]
)



Lima - Peru

View solution in original post

2 REPLIES 2
Vvelarde
Community Champion
Community Champion

@xhead

 

Hi Mike:

 

Use this and let me know if solve your issue

 

OrderTotal =
SUMX (
    SUMMARIZE (
        Table1,
        Table1[OrderID],
        "ORDERCOUNT", IF (
            SUM ( Table1[OrderCount] ) > 0,
            1,
            IF ( SUM ( Table1[OrderCount] ) < 0, -1, 0 )
        )
    ),
    [ORDERCOUNT]
)



Lima - Peru

That's exactly what I needed.

 

Thanks

Mike

 

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.