Forum Discussion
Create a Measure for the Number of days between two dates, but only counting work/business days
- 9 years ago
Hi,
as far as I can see the problem is that you try to use 2 different date columns on the datetable without having 2 different relationships.
My idea would be to try it with mathematic
1. Count all rows
2. Count all rows <= Start date
3. Count all rows >= End date
4. 1. - 2. - 3. = result
Try to use variables. Should looks like this.
CCD = var allrows = COUNTROWS(dim_Date[Date]) var exstart = CALCULATE(COUNTROWS(dim_Date[Date]),FILTER(dim_Date, dim_Date(Date)<=MAX(Start_date)) var exend = CALCULATE(COUNTROWS(dim_Date[Date]),FILTER(dim_Date, dim_Date(Date)>=MAX(End_date);USERELATIONSHIP(dim_Date(date),end_date)) return allrows - exstart - exend
Important is that you define in calculate a new relationship between the second date column and the datekey as mentioned in the beginning of my post.
I'm not sure if it works but this would be my way. Good luck
Hi,
as far as I can see the problem is that you try to use 2 different date columns on the datetable without having 2 different relationships.
My idea would be to try it with mathematic
1. Count all rows
2. Count all rows <= Start date
3. Count all rows >= End date
4. 1. - 2. - 3. = result
Try to use variables. Should looks like this.
CCD = var allrows = COUNTROWS(dim_Date[Date]) var exstart = CALCULATE(COUNTROWS(dim_Date[Date]),FILTER(dim_Date, dim_Date(Date)<=MAX(Start_date)) var exend = CALCULATE(COUNTROWS(dim_Date[Date]),FILTER(dim_Date, dim_Date(Date)>=MAX(End_date);USERELATIONSHIP(dim_Date(date),end_date)) return allrows - exstart - exend
Important is that you define in calculate a new relationship between the second date column and the datekey as mentioned in the beginning of my post.
I'm not sure if it works but this would be my way. Good luck
- GuillermoPuls9 years agoFrequent Visitor
Thanks Spuder, it's an interesting approach that works! I haven't started to deploy variables and it looks very practical.
I spent some more time looking at the relationships and by making them single I got the desired result.
Thanks