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

How to calculate number of transactions but excluding voided ones?

Hi Power BI experts,

 

I have a quick question that I hope you could kindly help me with. 

 

I'm working on a set up sales data which includes a list of transaction ID and Product price. Below is a sample list.

Screenshot 2021-11-15 140833.png

 

I was trying to work out the total # of transactions went through as each of the transaction means one sale we made. However, I noticed in this list, there are some transactions that were actually voided (maybe because the customers didn't want the product anymore so we issued them a refund). As you can see, Transaction ID 1001 appeared twice in the list. One product price is +50 and one product price is -50. 

 

If I use count rows to calculate total number of transactions, the result will not accurately reflect the actually # of transactions or sales we made. 

 

One method for me is to remove these transactions with + and - numbers completely from the original file. 

 

My question is, is there a DAX I can use to calculate the total number of successful transactions without removing the voided ones in the orginal dataset and also excluding in the calculation?

 

Thank you very much for your help in advance!

Cathy

 

2 ACCEPTED SOLUTIONS

@Anonymous change SUMX to COUNTX

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

This is how it should look like then:

 

Measure2 = 
COUNTX (
    FILTER (
        GROUPBY (
            'transaction',
            'transaction'[Transaction ID],
            "count", SUMX ( CURRENTGROUP (), 'transaction'[Product Price] )
        ),
        [count] <> 0
    ),
    [count]
)

 

 

View solution in original post

9 REPLIES 9
smpa01
Super User
Super User

@Anonymous  you can write a measure like this

Measure2 = 
SUMX (
    FILTER (
        GROUPBY (
            'transaction',
            'transaction'[Transaction ID],
            "sum", SUMX ( CURRENTGROUP (), 'transaction'[Product Price] )
        ),
        [sum] <> 0
    ),
    [sum]
)

 

smpa01_0-1637005822621.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

Hello, Thank you for showing me how to do this. Although I didn't get the expected result based on the DAX you provided, I still wanna say thank you for spending the time to help me! 🙂

Anonymous
Not applicable

Hi,

Thank you so much for your prompt help!

 

I just tried the dax you shared. Maybe my question wasn't so clear (sorry!). Could you please show me how to count the number of transaction IDs that with unvoided transactions please? In this case, the total number is 4 (ID#1002, 1003, 1004, 1005).

 

Thank you!

Cathy

This is how it should look like then:

 

Measure2 = 
COUNTX (
    FILTER (
        GROUPBY (
            'transaction',
            'transaction'[Transaction ID],
            "count", SUMX ( CURRENTGROUP (), 'transaction'[Product Price] )
        ),
        [count] <> 0
    ),
    [count]
)

 

 

Anonymous
Not applicable

Hi Daniel,

 

Based on my question yesterday, may I ask a follow up question please?

 

I'm working on similar dataset but this time I don't have transaction ID anymore. I have 'cutsomer membership account number', and 'transaction' that is associated with each of these customer accounts. See below sample data.

 

Screenshot 2021-11-16 111546.png

 

This time, the list not only has transactions that are voided (can cancel each other out) but I also noticed some transactions are marked 0 (also means no sales made). 

 

I also wanted to see the actual number of successful transactions in the dataset (this case is 4, unhighlight ones). Do I need to modify anything in DAX you shared with me yesterday to exclude those 0 transactions or is it already excluded along with the transactions that can cancel each other out?

 

Thanks a lot for your kind help!

Cathy

 

 

 

Anonymous
Not applicable

Thank you Daniel for your help! I got the result I wanted! 🙂 Thank you for spending the time to help me!

@Anonymous change SUMX to COUNTX

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Daniel_Fdrvc
Helper I
Helper I

If you understand correctly, then the identifiers 1001 and 1006 should not be counted at all? In this case, the result should be 4?

Anonymous
Not applicable

Hi Daniel,

 

Yes you are right. I only wanted to count 1002, 1003, 1004, 1005 and exclude all 1001 and 1006 because in reality 1001 and 1006 transactions mean $0 sale.

 

Best regards,

Cathy

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.