Need help with Distinctcount, DAX formula

shophoney

Active Member
Joined
Jun 16, 2014
Messages
281
Hi below is my formula for counting the number of transactions. But the issue is I now need to know the NET number of transactions. So if i had 16 sales and 2 returns the total I need is 14 transactions not 18.

TRANS# DISTINCT COUNT:=DISTINCTCOUNT('SALES TABLE'[TRANS#])

Can anyone help with this. Thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Pesumably you have a column that is negative or positive. Then

total = calculate(distinctcount(sales[trans]),sales[qty] > 0) - calculate(distinctcount(sales[trans]),sales[qty] < 0)
 
Upvote 0
Pesumably you have a column that is negative or positive. Then

total = calculate(distinctcount(sales[trans]),sales[qty] > 0) - calculate(distinctcount(sales[trans]),sales[qty] < 0)


This is what i tried:
TRANS# DISTINCT COUNT2:=CALCULATE(DISTINCTCOUNT('SALES TABLE'[TRANS#]),'SALES TABLE'[UNITS SOLD]>0)-CALCULATE(DISTINCTCOUNT('SALES TABLE'[TRANS#]),'SALES TABLE'[UNITS SOLD]<0)

Here's the strange part if I add up all the transactions it's correct. But yet the total shows a higher amount?

LOC#FULL NAMEADSUNITSRETAILTRANS# DISTINCT COUNT2
7000Jennifer F$17313$1,73310
Antonette P$18710$1,6819
Venessa B$24610$1,4736
Kaitlin E$1535$6104
Christina Q$854$5114
Andrea M$1694$3372
Julia F$2301$2301
Leyla M-$165-1-$165-1
7000 Total$17346$6,41034
Grand Total$17346$6,41034

<colgroup><col><col><col><col><col><col></colgroup><tbody>
</tbody>


Total should be 35 not 34?
 
Upvote 0
then you need this

Code:
[B]TRANS# DISTINCT COUNT2:=sumx(values([/B][B]'SALES TABLE'[TRANS#]),[/B][B]CALCULATE(DISTINCTCOUNT('SALES TABLE'[TRANS#]),'SALES TABLE'[UNITS SOLD]>0))-[/B][B]sumx(values([B]'SALES TABLE'[TRANS#]),[/B][/B][B]CALCULATE(DISTINCTCOUNT('SALES TABLE'[TRANS#]),'SALES TABLE'[UNITS SOLD]<0))[/B]

read here When to use SUM vs SUMX in DAX
 
Upvote 0
actually, take 2. This is better

Code:
TRANS# DISTINCT COUNT2 :=
CALCULATE (
    SUMX (
        VALUES ( 'SALES TABLE'[TRANS#] ),
        DISTINCTCOUNT ( 'SALES TABLE'[TRANS#] )
    ),
    'SALES TABLE'[UNITS SOLD] > 0
)
    - CALCULATE (
        SUMX (
            VALUES ( 'SALES TABLE'[TRANS#] ),
            DISTINCTCOUNT ( 'SALES TABLE'[TRANS#] )
        ),
        'SALES TABLE'[UNITS SOLD] < 0
    )


)
 
Upvote 0
Hi Matt.

I tried both. Option 2 gives the same result as before. For some reason the total is different then all the values manually added up. Never seen this before.

Option 3 gives $$ values in the thousands not sure. It is the number of transactions x the transactions???
 
Upvote 0
If you can post some sample data in a workbook configured, I can take a look for you. Did you read the article I posted above? this is a common 'problem' with known solutions. You just have to work out what the pivot table is doing that the grand total is not doing, and then use SUMX or similar to fix it.
 
Upvote 0
Hi Matt.

After a sleepless night. I've figured out the problem.

There was 1 sale that 2 associates sold 1 item each. That meant that it was 1 transaction for each of them, but at the same time it was only 1 transaction for the store.

So both answers are correct 34 sales took place but by associate it adds up to 35.

Not sure how to address it. And strange that the grand total in excel is not the sum of above, but more a calculation of the over all statement.

Maybe I should go back to using paper. LOL
 
Upvote 0

Forum statistics

Threads
1,214,800
Messages
6,121,641
Members
449,044
Latest member
hherna01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top