title: How to calculate daily population in DAX
body: <p>I'm trying to calculate the daily population of patients at our center for any given date using the patient's booking date (start date) and their release date -- using DAX and Power Pivot. I'm planning on using it in PowerBI eventually.  </p>
  
  <p>I've tried the formula below. I'm not getting any errors, but when I go to create a pivot table/chart in excel, I'm not getting the correct output. </p>
  
  <p>I'm only using two tables: 1) a main table with the patient data and 2) a date table (calendar) and have established a relationship between the two tables. </p>
  
  <p>The booking table has Patient ID, Booking Date, Release Date columns. I'd like to be able to create a graph showing the total population by day taking both dates into consideration.</p>
  
  <pre><code>DailyPop :=
  CALCULATE (
      COUNTROWS ( Patients ),
      FILTER (
          Patients,
          AND (
              Patients[Booking Date] &gt; MIN ( 'Calendar'[Date] ),
              Patients[Release Date] &lt; MAX ( 'Calendar'[Date] )
          )
      )
  )
  </code></pre>