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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
DimaMD
Solution Sage
Solution Sage

Count unique records in table by 3 calendar conditions

We have a table which includes 2 collums with dates, collum with ID and collum with owner. We need to count how many unique records are in the table on each owner, which considers our condition. 

 

Example of the table:

Date1OwnerIDDate2
16.06.2021Vika171230.06.2021
25.02.2021Vika151330.06.2021
25.02.2021Vika160830.06.2021
25.05.2021Vika163229.06.2021
25.05.2021Vika164830.06.2021
15.04.2021Taras164718.06.2021
31.05.2021Stepan165501.06.2021
16.06.2021Julia121325.06.2021
15.04.2021Julia141216.07.2021
25.03.2021Julia151530.07.2021
21.05.2021Julia164025.06.2021

 

The condition is:

date 1 < min calendar date

Date 2 >= min calendar date

Date 2<= max calemdar date

 

So for example. if we will put calendar dates like 01.06.2021-30.06.2021.

We need to count how many records meet our conditions. So in result we must receive:

Vika - 4

Taras - 1 

Stepan - 1 

Julia - 1

 

Please help us to solve this task. Thank you in advance!


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
1 ACCEPTED SOLUTION

Hi @DimaMD 

 

Try this one:

Count = 
VAR _Min =
    MIN ( 'Date'[Date] )
VAR _Max =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        ALLEXCEPT ( 'Table', 'Table'[Owner] ),
        'Table'[Date1] < _Min
            && 'Table'[Date2] >= _Min
            && 'Table'[Date2] <= _Max
    )

 

Output:

VahidDM_0-1633010192089.png

 

 

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

Appreciate your Kudos!!

 

View solution in original post

6 REPLIES 6
VahidDM
Super User
Super User

Hi @DimaMD 

 

Try this measure:

Count = 
Var _Min=MIN('Date'[Date])
Var _Max=MAX('Date'[Date])
return
CALCULATE(
    COUNTROWS('Table'),
    'Table'[Date1] < _Min,
    'Table'[Date2] >= _Min&&'Table'[Date2] <= _Max
    )

 

Output:

VahidDM_0-1633006982483.png

 

 

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

Appreciate your Kudos!!

 

 

Sorry @VahidDM , but this measure does not work, result is blank😥
I can't understand why your measure worked
Screenshot_2.jpg
Relationship between table and calendar Date1
Screenshot_1.jpg


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

Hi @DimaMD 

 

Try this one:

Count = 
VAR _Min =
    MIN ( 'Date'[Date] )
VAR _Max =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        ALLEXCEPT ( 'Table', 'Table'[Owner] ),
        'Table'[Date1] < _Min
            && 'Table'[Date2] >= _Min
            && 'Table'[Date2] <= _Max
    )

 

Output:

VahidDM_0-1633010192089.png

 

 

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

Appreciate your Kudos!!

 

Hi, @VahidDM 
Thank you, the measure worked


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
PaulOlding
Solution Sage
Solution Sage

Hi,

 

This measure gets your example result.  

Note, it uses DAX syntax introduced in September 2021 Desktop, so you'll need to be using that version.

 

Count = 
CALCULATE(
    COUNTROWS('Table'),
    'Table'[Date1] < MIN('Date'[Date]),
    'Table'[Date2] >= MIN('Date'[Date]),
    'Table'[Date2] <= MAX('Date'[Date])
    )

Sorry, but this measure does not work, result is blank
Screenshot_2.jpg

 


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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