Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powerbi 具有给定时间段和筛选器的开始日期和结束日期的DAX问题计数记录_Powerbi_Dax_M - Fatal编程技术网

Powerbi 具有给定时间段和筛选器的开始日期和结束日期的DAX问题计数记录

Powerbi 具有给定时间段和筛选器的开始日期和结束日期的DAX问题计数记录,powerbi,dax,m,Powerbi,Dax,M,我在PBI中有下表(“服务”): 该表包含向客户提供的所有服务。服务具有开始-和结束日期 我想做的是创建一个度量,对于给定的日期或日期范围,它返回在此期间接受服务的distinctCustomerID:s的数量 一些例子: 根据上表以及2019-01-01和2019-04-01之间的日期范围,度量值将返回不同的值3(与第2行、第4行和第5行匹配) 给定2019-07-01的单一日期,度量值将返回一个不同的值3(因为第1、2、3和4行的开始日期和结束日期都与该日期匹配) 在我的报告中,我还需要能

我在PBI中有下表(“服务”):

该表包含向客户提供的所有服务。服务具有开始-结束日期

我想做的是创建一个度量,对于给定的日期或日期范围,它返回在此期间接受服务的distinctCustomerID:s的数量

一些例子:

根据上表以及2019-01-01和2019-04-01之间的日期范围,度量值将返回不同的值3(与第2行、第4行和第5行匹配)

给定2019-07-01的单一日期,度量值将返回一个不同的值3(因为第1、2、3和4行的开始日期和结束日期都与该日期匹配)

在我的报告中,我还需要能够通过ServiceTypeID进行过滤

该表的定义如下:

Services = 
DATATABLE (
    "CustomerID"; INTEGER;
    "ServiceTypeID"; INTEGER;
    "ServiceStartDate"; DATETIME;
    "ServiceEndDate"; DATETIME;
    {
        { 1; 10; "2019-06-03"; "2019-09-01"  };
        { 2; 12; "2019-01-01"; "2019-12-31"  };
        { 2; 10; "2019-05-01"; "2019-09-01"  };
        { 3; 8; "2019-02-01"; "2019-08-01"  };
        { 4; 10; "2019-03-30"; "2019-06-01"  }
    }
) 
我尝试过像下面的代码那样定义度量值,但是我很难按ServiceTypeID进行过滤(度量值只是显示一个值,就好像我没有对ServiceTypeID应用过滤器一样)

活动服务的数量=
算计(
DISTINCTCOUNT(‘服务’[CustomerID]);
滤器(
所有选定的(‘服务’);
(
最小值('DateTable'[Date])>='Services'[ServiceStartDate]
&&最小值(DateTable[Date])=“服务”[ServiceStartDate]

&&MAX(DateTable[Date])我建议这个解决方案:

首先是模型:

然后,您可以编写此新度量:

NumActservices = 
 // Retrieve the current date
Var VrCurrentDate = MAX(DateTable[Date])

// Retrieve active Acts filter per ServiceID Within the current date
Var VrServicesInPeriode =  
    CALCULATETABLE(
        Services;
        FILTER(
            ALLEXCEPT(Services;Service[ServiceTypeID]);
            Services[ServiceStartDate]<VrCurrentDate
            &&
            Services[ServiceEndDate]>=VrCurrentDate
        )
    )

// Count Disctinct customer belonging to the previous table
Var VrResult = CALCULATE(   
                    DISTINCTCOUNT(Services[CustomerID]);
                    VrServicesInPeriode
                )


RETURN
VrResult
NumActservices=
//检索当前日期
Var VrCurrentDate=MAX(日期表[日期])
//在当前日期内检索每个ServiceID的活动Acts筛选器
变量VrServicesInPeriode=
可计算(
服务;
滤器(
ALLEXCEPT(服务;服务[ServiceTypeID]);
服务[ServiceStartDate]=VrCurrentDate
)
)
//统计属于上一个表的Disctinct客户
Var VrResult=计算(
DISTINCTCOUNT(服务[客户ID]);
VrServicesInPeriode
)
返回
VrResult
结果如下所示:


我提出以下解决方案:

首先是模型:

然后,您可以编写此新度量:

NumActservices = 
 // Retrieve the current date
Var VrCurrentDate = MAX(DateTable[Date])

// Retrieve active Acts filter per ServiceID Within the current date
Var VrServicesInPeriode =  
    CALCULATETABLE(
        Services;
        FILTER(
            ALLEXCEPT(Services;Service[ServiceTypeID]);
            Services[ServiceStartDate]<VrCurrentDate
            &&
            Services[ServiceEndDate]>=VrCurrentDate
        )
    )

// Count Disctinct customer belonging to the previous table
Var VrResult = CALCULATE(   
                    DISTINCTCOUNT(Services[CustomerID]);
                    VrServicesInPeriode
                )


RETURN
VrResult
NumActservices=
//检索当前日期
Var VrCurrentDate=MAX(日期表[日期])
//在当前日期内检索每个ServiceID的活动Acts筛选器
变量VrServicesInPeriode=
可计算(
服务;
滤器(
ALLEXCEPT(服务;服务[ServiceTypeID]);
服务[ServiceStartDate]=VrCurrentDate
)
)
//统计属于上一个表的Disctinct客户
Var VrResult=计算(
DISTINCTCOUNT(服务[客户ID]);
VrServicesInPeriode
)
返回
VrResult
结果如下所示:


谢谢@jbfreegomes!谢谢@jbfreegomes!