Forum Discussion
Anonymous
3 years agoNot applicable
DAX - Count Days Between two date fields on a Date Axis
Hello, I'm trying to use DAX to count every day between two date fields for a large dataset and create a stacked column chart broken out by Program. You can do this in excel by means of the COUN...
- 3 years ago
Hi,
hope this will help you. Dynamic measure based on your calendar.
Count Correct Rows =var date_ref = SELECTEDVALUE(dim_calendar[Date])returnCOUNTX(FILTER('Sample';AND('Sample'[Status Start Date] <= date_ref;'Sample'[Status End Date]>=date_ref));COUNTROWS('Sample'))You can use Program column as you want. No relationship needed.
bolfri
Solution Sage
3 years agoHi,
hope this will help you. Dynamic measure based on your calendar.
Count Correct Rows =
var date_ref = SELECTEDVALUE(dim_calendar[Date])
return
COUNTX(
FILTER('Sample';AND('Sample'[Status Start Date] <= date_ref;'Sample'[Status End Date]>=date_ref));
COUNTROWS('Sample')
)
You can use Program column as you want. No relationship needed.
- Anonymous3 years agoNot applicable
Hi bolfri ,
This Solution does exactly as expected. Thank you!
One follow-up question. I'd like to show date hierarchy on my axis, with date rolling up to Month & Quarter. PBI will not accept the Month or Quarter axis - visual shows blank when I try that. Is there a way to rewrite this to account for those? Can they be included as variables?
Thanks again!
- bolfri3 years ago
Solution Sage
Sure. I needed to change it a little, but this i a result:
Count Correct Rows - Aggregatable =var min_date = FIRSTDATE(dim_calendar[Date])var max_date = LASTDATE(dim_calendar[Date])returnCOUNTX(FILTER('Sample';AND(OR(OR(//Scenario 1AND('Sample'[Status Start Date]<=min_date;'Sample'[Status End Date]>=max_date);//Scenario 2AND('Sample'[Status Start Date]>=min_date;'Sample'[Status End Date]<=max_date));OR(//Scenario 3AND('Sample'[Status Start Date]<=min_date;AND('Sample'[Status End Date]>=min_date;'Sample'[Status End Date]<=max_date));//Scenario 4AND(AND('Sample'[Status Start Date]>=min_date;'Sample'[Status Start Date]<=max_date);'Sample'[Status End Date]>=max_date)));//Exclude all records with wrong data, when start is after end'Sample'[Status Start Date] <= 'Sample'[Status End Date]));COUNTROWS('Sample'))Graphic representation on each scenario:Result:
Count Correct Rows - Aggregatable - new oneCount Correct Rows - old one, that works only for day representation