Powerbi 如何按每月的状态计算客户数量,以了解每月有多少客户处于活动状态或正在加入

Powerbi 如何按每月的状态计算客户数量,以了解每月有多少客户处于活动状态或正在加入,powerbi,Powerbi,我正在将报告从Cooladata(BigQuery)转移到Power BI。 我有一个不同状态(在线、在线、禁用)的客户表。对于每个状态,我都有一个日期(如果发生了)。我想得到的是每个月有多少客户处于这种状态。例如,如果我有2个客户在3月份开业,2个在4月份开业,2个在5月份开业,我需要在5月份看到6个客户。但这并不是5月份这些客户中有人被移动到禁用状态的累积原因。实际上,我只是简单地检查在特定月份有多少客户处于禁用状态 ! 在BigQuery中,我创建了一个表,该表返回每个月的最后一个日期,并

我正在将报告从Cooladata(BigQuery)转移到Power BI。 我有一个不同状态(在线、在线、禁用)的客户表。对于每个状态,我都有一个日期(如果发生了)。我想得到的是每个月有多少客户处于这种状态。例如,如果我有2个客户在3月份开业,2个在4月份开业,2个在5月份开业,我需要在5月份看到6个客户。但这并不是5月份这些客户中有人被移动到禁用状态的累积原因。实际上,我只是简单地检查在特定月份有多少客户处于禁用状态

!

在BigQuery中,我创建了一个表,该表返回每个月的最后一个日期,并检查客户开始登机或更改为live或Disabled状态的日期是否早于这些日期。同一客户在3月、4月、5月等进行检查。 我每月检查一次这种情况,从而按类型获得所需的账户总额

    SELECT count( case when ChangedToLiveOn<=last_day_of_month and (DisabledOn>last_day_of_month OR DisabledOn is null) then 1 end) as Clients_Live, 
           count(case when StartedOnBoardingDate<=last_day_of_month and (ChangedToLiveOn>last_day_of_month OR ChangedToLiveOn is null) and (DisabledOn>last_day_of_month OR DisabledOn is null) then 1 end) OnBoarding.
但我不能把它移到Power Bi

    DECLARE @date DATETIME ,
@DAtediffM INT;

SET @date = GETDATE()
SET @DatediffM = 0

WHILE @DatediffM >= -12
BEGIN

DECLARE @last_day_of_month DATETIME
SET @last_day_of_month= EOMONTH ( @date, @DatediffM  )
SET @DatediffM = @DatediffM - 1

SELECT @last_day_of_month, 
COUNT(CASE WHEN ntw_ChangedToLiveOn<=@last_day_of_month and (ntw_DisabledOn>@last_day_of_month OR ntw_DisabledOn is null)  then 1 END) 
+  COUNT(CASE WHEN ntw_StartedOnBoardingDate<=@date and (ntw_ChangedToLiveOn>@last_day_of_month OR ntw_ChangedToLiveOn is null) and  (ntw_DisabledOn>@last_day_of_month OR ntw_DisabledOn is null)  then 1 END) AS Total ,
   COUNT(CASE WHEN ntw_ChangedToLiveOn<=@last_day_of_month and (ntw_DisabledOn>@last_day_of_month OR ntw_DisabledOn is null)   then 1 end) AS Clients_Live,
   COUNT(CASE WHEN ntw_StartedOnBoardingDate<=@date and (ntw_ChangedToLiveOn>@last_day_of_month OR ntw_ChangedToLiveOn is null) and 
(ntw_DisabledOn>@last_day_of_month OR ntw_DisabledOn is null)  then 1 end) OnBoarding,

FROM AccountBase 

WHERE  ((DATEDIFF(month,ntw_ChangedToLiveOn, GETDATE()) <=12  OR ntw_ChangedToLiveOn is null) or(DATEDIFF(month,ntw_DisabledOn, GETDATE()) <=12  OR ntw_DisabledOn is null))  



Print @last_day_of_month
END