How to calculate daily percentage over month on month volume?

旧街凉风 提交于 2020-01-16 16:13:13

问题


I am trying to sum the volume based on month and year for certain records in the given data and then for the given month I am trying to calculate the daily percentage arrival in power bi

for the record Person A,1/1/2018,Project,100,1 it should be 100/220

Below is the example data:

Resource Name,Month,RecordType,Actual,Flag
Person A,1/1/2018,Project,100,1
Person A,1/2/2018,Support,40,1
Person A,1/3/2018,Training,50,1
Person A,1/4/2018,Unavailable,30,1
Person A,2/1/2018,Project,80,1
Person A,2/2/2018,Support,50,1
Person A,2/3/2018,Training,20,1
Person A,2/4/2018,Unavailable,50,1
Person A,3/1/2018,Project,150,1
Person A,3/2/2018,Support,10,1
Person A,3/3/2018,Training,20,1
Person A,3/4/2018,Unavailable,20,1
Person B,1/1/2018,Project,50,0
Person B,1/1/2018,Support,100,0
Person B,1/1/2018,Training,45,0
Person B,1/1/2018,Unavailable,5,0
Person B,2/1/2018,Project,90,0
Person B,2/1/2018,Support,80,0
Person B,2/1/2018,Training,10,0
Person B,2/1/2018,Unavailable,20,0
Person B,3/1/2018,Project,180,0
Person B,3/1/2018,Support,5,0
Person B,3/1/2018,Training,10,0
Person B,3/1/2018,Unavailable,5,0

Tried below but getting error

  Daily_percentage1 = CALCULATE(data1[Actual])/CALCULATE(SUM(data1[Actual]),FILTER(ALLEXCEPT(data1,data1[Month].[Month],data1[Month].[Year]),data1[Flag]=1))

Expedted Output

Resource Name,RecordType,Flag,Month,Actual,Daily_percentage1
Person A,Project,1,1/1/2018 0:00,100,0.454545455
Person A,Support,1,1/2/2018 0:00,40,0.181818182
Person A,Training,1,1/3/2018 0:00,50,0.227272727
Person A,Unavailable,1,1/4/2018 0:00,30,0.136363636
Person A,Project,1,2/1/2018 0:00,80,0.4
Person A,Support,1,2/2/2018 0:00,50,0.25
Person A,Training,1,2/3/2018 0:00,20,0.1
Person A,Unavailable,1,2/4/2018 0:00,50,0.25
Person A,Project,1,3/1/2018 0:00,150,0.75
Person A,Support,1,3/2/2018 0:00,10,0.05
Person A,Training,1,3/3/2018 0:00,20,0.1
Person A,Unavailable,1,3/4/2018 0:00,20,0.1
Person B,Project,0,1/1/2018 0:00,50,
Person B,Support,0,1/1/2018 0:00,100,
Person B,Training,0,1/1/2018 0:00,45,
Person B,Unavailable,0,1/1/2018 0:00,5,
Person B,Project,0,2/1/2018 0:00,90,
Person B,Support,0,2/1/2018 0:00,80,
Person B,Training,0,2/1/2018 0:00,10,
Person B,Unavailable,0,2/1/2018 0:00,20,
Person B,Project,0,3/1/2018 0:00,180,
Person B,Support,0,3/1/2018 0:00,5,
Person B,Training,0,3/1/2018 0:00,10,
Person B,Unavailable,0,3/1/2018 0:00,5,

回答1:


Everyone has their own choice, I would like to handle this in one measure rather having 2 separate measures.

Total_Percentage = 
VAR TotalPerMonth =
    CALCULATE (
        SUM ( data1[Actual] ),
        FILTER ( data1, data1[Month].[Month] = EARLIER ( data1[Month].[Month] ) ),
        FILTER ( data1, data1[Month].[Year] = EARLIER ( data1[Month].[Year] ) ),
        FILTER ( data1, data1[Flag] = 1 )
    )
RETURN
    DIVIDE ( data1[actual], TotalPerMonth, 0 )
// taking care of divide by zero error



回答2:


I got the answer for my own question if anyone have better answer let me know I created two columns

TotalPerMonth =
CALCULATE (
    SUM ( data1[Actual] ),
    FILTER ( data1, data1[Month].[Month] = EARLIER ( data1[Month].[Month] ) ),
    FILTER ( data1, data1[Month].[Year] = EARLIER ( data1[Month].[Year] ) ),
    FILTER ( data1, data1[Flag] = 1 )
)

Total_percentage =
100 * ( data1[Actual] / data1[TotalPerMonth] )


来源:https://stackoverflow.com/questions/55656831/how-to-calculate-daily-percentage-over-month-on-month-volume

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