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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Qotsa
Helper V
Helper V

Count with conditions

Hi,

 

Need to count the 'carerid' column entries with some conditions applied based on column 'startdate'.

 

Conditions

  • Every carerid is counted at least once.
  • Only count carerid more than once if there is greater than 1 day between the next 'startdate' for that 'carerid'.

 

Qotsa_0-1615381282011.png

 

I have tried this measure but it doesn't return any results and I do understand why as it is comparing the same values.

Test = CALCULATE(COUNT('powerbi114 holidays'[carerId]),DATEDIFF('powerbi114 holidays'[startDate],'powerbi114 holidays'[startDate],DAY) > 1)

 

1 ACCEPTED SOLUTION

@Qotsa 

updated the DAX,

please check if it's correct now

Column = 
VAR _minindex=minx(FILTER('powerbi114 holidays','powerbi114 holidays'[carerid]=EARLIER('powerbi114 holidays'[carerId])),'powerbi114 holidays'[Index])
return  if('powerbi114 holidays'[Index]=_minindex,1,if('powerbi114 holidays'[startdate]-MAXX(FILTER('powerbi114 holidays','powerbi114 holidays'[Index]=EARLIER('powerbi114 holidays'[Index])-1),'powerbi114 holidays'[startdate])>1,1,0))




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

7 REPLIES 7
ryan_mayu
Super User
Super User

@Qotsa 

is your date type dd/mm/yyyy? why the result for careid 17 is 1?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu 

 

Yes, date is dd/mm/yyyy.

carerid = 1 because there is not greater than 1 day between each entry.


If the dates were

05/03/21

06/03/21

08/03/21

 

05 & 06 is counted as 1

08 is counted as 1 as greater than 1 day between 06 & 08.

 

the desired outcome is =2

 

 

 

@Qotsa 

here is a wordaround for you.

1. create an index column in PQ

2. use DAX to create a column

Column = 
VAR _minindex=minx(FILTER('Table','Table'[careid]=EARLIER('Table'[careid])),'Table'[Index])
return if('Table'[Index]=_minindex,1,if(MAXX(FILTER('Table','Table'[Index]=EARLIER('Table'[Index])+1),'Table'[startdate])-'Table'[startdate]>1,1,0))

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi,

 

Thanks both for your replies.

 

Not getting the desired results with your formulas.

 

I have uploaded the pbix here

if you could look I would appreciate it.

 

Qotsa_2-1615542295472.png

 

 

@Qotsa 

updated the DAX,

please check if it's correct now

Column = 
VAR _minindex=minx(FILTER('powerbi114 holidays','powerbi114 holidays'[carerid]=EARLIER('powerbi114 holidays'[carerId])),'powerbi114 holidays'[Index])
return  if('powerbi114 holidays'[Index]=_minindex,1,if('powerbi114 holidays'[startdate]-MAXX(FILTER('powerbi114 holidays','powerbi114 holidays'[Index]=EARLIER('powerbi114 holidays'[Index])-1),'powerbi114 holidays'[startdate])>1,1,0))




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu 

Thank you. works great.

 

@amitchandak 
Thanks for your help also.

amitchandak
Super User
Super User

@Qotsa , try like

 

Test = CALCULATE(COUNTX(filter(values('powerbi114 holidays'[carerId]),DATEDIFF(min('powerbi114 holidays'[startDate]),max('powerbi114 holidays'[startDate]),DAY) > 1),[carerId]))

 

or

 

Test = CALCULATE(COUNTX(filter(values('powerbi114 holidays'[carerId]),DATEDIFF(min('powerbi114 holidays'[startDate]),max('powerbi114 holidays'[startDate]),DAY) > 1),[carerId]), allexcept('powerbi114 holidays'[carerId]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors