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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

DAX query for COUNT with WHERE condition

Hi, I have table with custid, createddate and cancelled date. I want to create a calcualted measure using DAX for couting number of custid's WHERE createdate is BETWEEN April1st - March31t financial year BUT EXCLUDE those custid's WHERE  cancelled date is BETWEEN April1st - March31t financial year.

 

Can someone please help me with that DAX query ? Many Thanks

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Assume you use a date table and FY is column in date table and it is selected in a slicer

 

If date table is independent and joined to any of these columns

 

measure =
var _max = maxx(ALLSELECTED('Date'),'Date'[Date])
var _min = minx(ALLSELECTED('Date'),'Date'[Date])
return
calculate(count(Table[customer_id]), filter(Table, Table[createdate] >=Min && Table[createdate] <=Max && Table[cancelled date] >=Min && Table[cancelled date] <=Max ))

 

 

And if date table is joined to createdate
measure =
var _max = maxx(ALLSELECTED('Date'),'Date'[Date])
var _min = minx(ALLSELECTED('Date'),'Date'[Date])
return
calculate(count(Table[customer_id]), filter(Table, Table[cancelled date] >=Min && Table[cancelled date] <=Max ))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi Amit, But I cannot see your query filtering for the below conditon for both created and cancelled date . Am i missing something ?

 

BETWEEN April1st - March31t

Anonymous
Not applicable

Hi Thanks Amit. Yes I have a seperate DATE table in my model and its got relation with both those columns. ACTIVE relation on the created date and non-active relation on the cancelled date.

 

Thanks

 

amitchandak
Super User
Super User

@Anonymous , Assume you use a date table and FY is column in date table and it is selected in a slicer

 

If date table is independent and joined to any of these columns

 

measure =
var _max = maxx(ALLSELECTED('Date'),'Date'[Date])
var _min = minx(ALLSELECTED('Date'),'Date'[Date])
return
calculate(count(Table[customer_id]), filter(Table, Table[createdate] >=Min && Table[createdate] <=Max && Table[cancelled date] >=Min && Table[cancelled date] <=Max ))

 

 

And if date table is joined to createdate
measure =
var _max = maxx(ALLSELECTED('Date'),'Date'[Date])
var _min = minx(ALLSELECTED('Date'),'Date'[Date])
return
calculate(count(Table[customer_id]), filter(Table, Table[cancelled date] >=Min && Table[cancelled date] <=Max ))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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