Forum Discussion

GuillermoPuls's avatar
GuillermoPuls
Frequent Visitor
9 years ago
Solved

Create a Measure for the Number of days between two dates, but only counting work/business days

Hi,   I would like to get a measure that is returning the number of days that a contract is current in a given month.   I have a table with dates (It's a unique list with continuous dates, Week d...
  • spuder's avatar
    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