Distinct Count problem

shophoney

Active Member
Joined
Jun 16, 2014
Messages
281
[FONT=&quot]Hi, I have an issue with a DAX formula and have spent over a week trying to resolve it.[/FONT]
[FONT=&quot]I would like to know the number of sale transactions each day. But here’s the quandary:[/FONT]

  • If the total number of units sold after returns is zero, ignore transaction.
  • If total units sold is >0 then count it 1
  • If total units sold is less <0 count it -1
[FONT=&quot]Here is my current formula:[/FONT]
[FONT=&quot]TRANS# DISTINCT COUNT:=CALCULATE(DISTINCTCOUNT(‘SALES TABLE'[TRANS#]),’SALES TABLE'[UNITS SOLD]>0)-CALCULATE(DISTINCTCOUNT(‘SALES TABLE'[TRANS#]),’SALES TABLE'[UNITS SOLD]<0)

[/FONT]

[FONT=&quot]Correct answer should be 43 units sold and 32 transactions[/FONT]
[FONT=&quot]The issue is with transaction 206, we had a return and a sale in the same transaction. So it met both criteria being both +1 and -1 = 0[/FONT]
[FONT=&quot] [/FONT]
Column Labels
9200
Row LabelsTRANS# DISTINCT COUNTSALES TOTAL UNITS SOLD
08/14/18
17211
173-1-1
17411
17500
17611
17700
17811
17912
18013
18111
18213
18311
18411
18511
20511
20603
20711
20811
20911
21000
21111
21211
21311
21411
21511
21611
217-1-3
21811
21912
22013
22112
22211
22311
22412
22511
22612
22711
22811
22911
08/14/18 Total3143

<colgroup><col><col><col></colgroup><tbody>
</tbody>
[FONT=&quot]Thanks[/FONT]
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I don't think I understand your question, otherwise this would just be something like:

Code:
Measure:=
VAR TotalSoldUnits = SUM ( 'Sales Table'[Units Sold])

RETURN
SWITCH (
    TRUE(),
    TotalUnitsSold > 0, 1,
    TotalUnitsSold <0, -1,
    0
)
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,676
Members
448,977
Latest member
moonlight6

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