Forum Discussion

msimmonsmcse's avatar
msimmonsmcse
Icon for Helper I rankHelper I
6 years ago
Solved

Counting dates in a filtered date range

Hello, PowerBi newbie here: I have the following two tables below and I am trying to make a measure that calculates: Number of Business Days – Returns the count of IsBusinessDays in a filtered repo...
  • nandukrishnavs's avatar
    6 years ago

    msimmonsmcse 

     

    Try this example 

    NumberOfBusDays =
    VAR _maxdate =
        MAX ( 'Date Table'[Date] )
    VAR _mindate =
        MIN ( 'Date Table'[Date] )
    VAR _hiredate =
        CALCULATE ( SELECTEDVALUE ( 'Member Table'[Hire Date] ) )
    VAR _r =
        CALCULATE (
            COUNT ( 'Date Table'[Date] ),
            'Date Table'[Date] > _hiredate
                && 'Date Table'[Date] < _maxdate,
            'Date Table'[IsBusinessDay] = 1
        ) 
    // if the hire date is not in the date range, return blank.    
    VAR _result =
        IF ( _hiredate < _mindate || _hiredate > _maxdate, BLANK (), _r )
    RETURN
        _result

     

    Did I answer your question? Mark my post as a solution!
    Appreciate with a kudos
    🙂

  • msimmonsmcse's avatar
    msimmonsmcse
    6 years ago

    Thanks! Its close, but I have one issue. Returning BLANK() for the result will not work. It needs to return a sum of the number of business days in that time period. I tried adding SUM('Date Table'[IsBusinessDay]), but it is not totaling correctly and affects the downstream calculations that us that NumberOfBusinessDays measure. For example, Hourly Capacity is 8*NumberofBusinessDays:

     

    NameNumberOfBusinessDaysHourly Capacity
    Member 1540
    Member 2540
    Member 3324
    TOTAL540