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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
pezakas
Helper I
Helper I

Counting distinct records (and the most updated) within a date range selected by user

Hello community!

Here is my data sample:

CST_IDREF_DTFRST_NMLST_NMADDRSS
10011/1/2023PAULSMITHHERE 16
100210/1/2023JOHNWHITETHERE 12
100310/1/2023STACYBROWNTHERE 15
10042/2/2023OLIVERROSEUP 205
10052/2/2023NICKMILESDOWN 14
10062/2/2023SAMANTHARODRIGUEZUP&DOWN 25
10072/2/2023IRENEMORALESBEHIND 10
10082/2/2023LULUDAVISINFRONT 12
10092/2/2023THEOBOLDLAWRENCEFARAWAY 120
100115/3/2023PAULSMITHDOWN 15
101016/3/2023THALIAAPPLEUP&DOWN 28
101130/3/2023TAMARABOYDUP&DOWN 56
101230/3/2023GEORGEROBINSONDOWN 19
101312/4/2023NEILFLOYDUP 298
100715/4/2023IRENEMORALESFARAWAY 120
101517/4/2023ALVINVARGASFARAWAY 121

 

I want to build a linechart like the below one:

pezakas_0-1697709700101.png

I want to show the progress of the distinct count of the customers within a selected date range from a slicer.
As you can see in the table there are 2 records with same CST_ID. Thats because their adress has been updated. So i dont want to double count them, just count the most updated record. In case user tries drill through i want him to see the most updated info of the customer.
Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @pezakas ,

 

If your slicer selects less than April 14, 2023, then any data from April 15, 2023 will be filtered out and only the largest number of dates in the interval less than April 14, 2023 will be counted

 

Here are the steps you can follow:

1. Create measure.

Measure =
var _select=SELECTEDVALUE('Table'[REF_DT])
var _maxdate=
MAXX(
    FILTER(ALLSELECTED('Table'),
    'Table'[CST_ID]=MAX('Table'[CST_ID])),[REF_DT])
return
COUNTX(
    FILTER(ALL('Table'),    'Table'[REF_DT]=_maxdate&&YEAR('Table'[REF_DT])=YEAR(MAX('Table'[REF_DT]))&&MONTH('Table'[REF_DT])=MONTH(MAX('Table'[REF_DT]))),[CST_ID])

2. Result:

 

vyangliumsft_0-1698137331074.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @pezakas ,

 

If your slicer selects less than April 14, 2023, then any data from April 15, 2023 will be filtered out and only the largest number of dates in the interval less than April 14, 2023 will be counted

 

Here are the steps you can follow:

1. Create measure.

Measure =
var _select=SELECTEDVALUE('Table'[REF_DT])
var _maxdate=
MAXX(
    FILTER(ALLSELECTED('Table'),
    'Table'[CST_ID]=MAX('Table'[CST_ID])),[REF_DT])
return
COUNTX(
    FILTER(ALL('Table'),    'Table'[REF_DT]=_maxdate&&YEAR('Table'[REF_DT])=YEAR(MAX('Table'[REF_DT]))&&MONTH('Table'[REF_DT])=MONTH(MAX('Table'[REF_DT]))),[CST_ID])

2. Result:

 

vyangliumsft_0-1698137331074.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

devesh_gupta
Impactful Individual
Impactful Individual

@pezakas 

You can use Power Query to create a new table that only includes the most recent record for each customer. Then, you can create a measure to count the distinct customers within the selected date range. Here are the steps:

  1. Create a New Table with Most Recent Records:

  2. Create a Measure to Count Distinct Customers:

 

Distinct Customer Count = DISTINCTCOUNT('NewTable'[CST_ID])​

 

If you find this insightful, please provide a Kudo and accept this as a solution.

How is this solution gonna work in case the user select a range before 15/04/2023? Cause in this scenario, the most updated record for the CST_ID=1007 is the one on 02/02/2023. By keeping only the Top rows in another table in a decending order by CST_ID in the first place, i am gonna loose that record, right?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors