How to calculate daily population in DAX

前提是你 提交于 2019-12-11 15:17:48

问题


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.

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.

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.

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.

DailyPop :=
CALCULATE (
    COUNTROWS ( Patients ),
    FILTER (
        Patients,
        AND (
            Patients[Booking Date] > MIN ( 'Calendar'[Date] ),
            Patients[Release Date] < MAX ( 'Calendar'[Date] )
        )
    )
)

回答1:


You can add an extra column on your date table:

PatientCount:= SUMX(Patients,IF(Patients[Booking Date]<='Calendar'[Date] && Patients[Release Date]>='Calendar'[Date],1,0))


来源:https://stackoverflow.com/questions/55961210/how-to-calculate-daily-population-in-dax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!