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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Kiki
Advocate II
Advocate II

DISTINCTCOUNT excluding certain records

Hello. I need some help.

 

Below is an example of my model:

Kiki_2-1656063310495.png

 

 

I am trying to get a count of all transactions with a First Transaction Date before 01/02/2022 (based on slicer selection) using:

 

CALCULATE(DISTINCTCOUNT('Transaction Table'[Rreference]),

FILTER('Transaction Table','Transaction Table'[First Transaction Date]<MIN('Date Table'[Date].[Date])

 

However, the above gives me a count of 2, instead of 3, omitting reference 167 because it doesn’t have a transaction date in the month of February 2022.

 

Any help will be much appreciated.

 

Thanks

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Kiki 
Please try

=
CALCULATE (
    DISTINCTCOUNT ( 'Transaction Table'[Rreference] ),
    'Transaction Table'[First Transaction Date] < MIN ( 'Date Table'[Date] ),
    CROSSFILTER ( 'Transaction Table'[Transaction Date], 'Date Table'[Date], NONE )
)

View solution in original post

8 REPLIES 8
tamerj1
Super User
Super User

Hi @Kiki 
Please try

=
CALCULATE (
    DISTINCTCOUNT ( 'Transaction Table'[Rreference] ),
    'Transaction Table'[First Transaction Date] < MIN ( 'Date Table'[Date] ),
    CROSSFILTER ( 'Transaction Table'[Transaction Date], 'Date Table'[Date], NONE )
)

YES!! Thank you so much! It works!

SpartaBI
Community Champion
Community Champion

@tamerj1 my man 🙂

☺️

SpartaBI
Community Champion
Community Champion

@Kiki please try:

CALCULATE(DISTINCTCOUNT('Transaction Table'[Rreference]),

'Transaction Table'[First Transaction Date]<MIN('Date Table'[Date].[Date])
)


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Hi. This is not working unfortunately.

SpartaBI
Community Champion
Community Champion

@Kiki ok, no worries 🙂 will get there. 
Can you maybe share the file / sample of the file with fake data and explain there in a text box the desired output you want to get.

Hi, 

 

I hope this works?

 

Transaction Table
ReferenceTransaction DateFirst Transaction DateLast Date
12301/01/201901/01/201901/03/2022
12301/05/202001/01/201901/03/2022
12301/02/202201/01/201901/03/2022
14501/02/202101/02/202101/03/2022
14501/03/202201/02/202101/03/2022
16701/03/201801/03/2018 
16701/01/202201/03/2018 
18701/01/201701/01/2017 
18715/02/202201/01/2017 

 

CALCULATE(DISTINCTCOUNT('Transaction Table'[Rreference]),
FILTER('Transaction Table','Transaction Table'[First Transaction Date]<MIN('Date Table'[Date].[Date])
&&OR('Transaction Table'[Last Transaction Date]>=MIN('Date Table'[Date].[Date]),ISBLANK('Transaction Table'[Last Transaction Date])))

 

I am expecting the count to be 4 i.e. 123, 145,167 & 187 because all of these references have a First Transaction Date of before the 1st of February 2022, and a Last Transaction Date of either after the 1st of February 2022 or blank.

 

However, I am getting a count of 2 i.e. 123 & 187, and I think this because these references have a Transaction Date within the month of February 2022 i.e. the selected date in the slicer.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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