如何在 DAX 中计算每日人口 [英] How to calculate daily population in DAX

查看:19
本文介绍了如何在 DAX 中计算每日人口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用患者的预订日期(开始日期)和他们的发布日期(使用 DAX 和 Power Pivot)来计算我们中心在任何给定日期的每日患者人数.我计划最终在 PowerBI 中使用它.

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.

我试过下面的公式.我没有收到任何错误,但是当我在 excel 中创建数据透视表/图表时,我没有得到正确的输出.

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.

我只使用了两个表:1) 一个包含患者数据的主表和 2) 一个日期表(日历),并在这两个表之间建立了关系.

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.

预订表包含患者 ID、预订日期、发布日期列.我希望能够创建一个图表,显示每天的总人口,同时考虑这两个日期.

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] )
        )
    )
)

推荐答案

您可以在日期表上添加额外的列:

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))

这篇关于如何在 DAX 中计算每日人口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆