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
Compacted
New Member

Power bi dates diff conditional count

I am new to power bi and i need to count the number of times that a employee has the same issue code in less than 50 days.

Employee | Code | Date

01 | 101 | mm/dd/yyyy

02 | 101 | mm/dd/yyyy

03 | 101 | mm/dd/yyyy

02 | 101 | mm/dd/yyyy

01 | 100 | mm/dd/yyyy

03 | 101 | mm/dd/yyyy

03 | 102 | mm/dd/yyyy

I tried to get the days using datediff but im not so sure how to implement the conditionals to count that.

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Compacted 

 

As you said, if your data sets are less than 50 days, you can count directly.

1. Calculated column

 

Count =
CALCULATE (
    COUNT ( 'Table'[ Code ] ),
    FILTER (
        'Table',
        'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
            && 'Table'[ Code ] = EARLIER ( 'Table'[ Code ] )
    )
)

 

vzhangti_0-1636681568796.jpeg

vzhangti_1-1636681604276.png

 

 2. Measure

 

Measure =
CALCULATE (
    COUNT ( 'Table'[ Code ] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Employee ] = MAX ( 'Table'[Employee ] )
            && 'Table'[ Code ] = MAX ( 'Table'[ Code ] )
    )
)

 

vzhangti_2-1636681656907.png

 

Best Regards,

Community Support Team _Charlotte

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
v-zhangti
Community Support
Community Support

Hi, @Compacted 

 

As you said, if your data sets are less than 50 days, you can count directly.

1. Calculated column

 

Count =
CALCULATE (
    COUNT ( 'Table'[ Code ] ),
    FILTER (
        'Table',
        'Table'[Employee ] = EARLIER ( 'Table'[Employee ] )
            && 'Table'[ Code ] = EARLIER ( 'Table'[ Code ] )
    )
)

 

vzhangti_0-1636681568796.jpeg

vzhangti_1-1636681604276.png

 

 2. Measure

 

Measure =
CALCULATE (
    COUNT ( 'Table'[ Code ] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Employee ] = MAX ( 'Table'[Employee ] )
            && 'Table'[ Code ] = MAX ( 'Table'[ Code ] )
    )
)

 

vzhangti_2-1636681656907.png

 

Best Regards,

Community Support Team _Charlotte

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

Greg_Deckler
Super User
Super User

@Compacted Assuming you put Employee and Code into a table visual you could use this measure:

Measure =
  VAR __Employee = MAX('Table'[Employee])
  VAR __Code = MAX('Table'[Code])
  VAR __LastDate = MAX('Table'[Date])
  VAR __MinDate = __LastDate - 50
RETURN
  COUNTROWS(FILTER('Table',[Date]>=__LastDate))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hey thanks for the help, i've tried using the solution above but it keeps returning ones in every row, and in the end the total is just the number of rows. There are 10 cases that are less than 50 days in the dataset that i am using so i was expecting to see something similar as the count result.

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.