Search code examples
powerbidaxdaxstudio

DAX - What % of Months hit the Target


I am trying to create a measure to calculate what % of months that TOP2 surveys hit my target.

Here is my Dataset.

Dept_Surveys

enter image description here

I got 100% TOP2 surveys in Nov-2020,30% in Dec-2020 and 75% in Jan-2021

I have one more table which contains the actual targets for each department.

Dept_Targets

enter image description here

Var __TOP2%byMonth =
SUMMARIZE (
    Dept_Surveys,
    Dept_Surveys[Dept],
    Dept_Surveys[MM-YY],
    "@Perc",
        DIVIDE (
            CALCULATE (
                DISTINCTCOUNT ( Dept_Surveys[SurveyID] ),
                FILTER ( Dept_Surveys, Dept_Surveys[category] = "TOP2" )
            ),
            CALCULATE ( DISTINCTCOUNT ( Dept_Surveys[SurveyID] ) )
        ) * 100
)

I am getting the below results from this DAX.

enter image description here

Total_Months =
CALCULATE (
    DISTINCTCOUNT ( Dept_Surveys[MM-YY] )
)

So here, my marketing dept hit the target in Nov-2020 and Jan-2021 (which is greater than 70 from Dept_Targets) I need to calculate What % of months actually hit the target.

here i should get 2/3 = 65%

I need to do compare if TOP2 survey % hit the actual target and finally I need to measure what % of months hit the target


Solution

  • We have model:

    enter image description here

    Perc = 
            DIVIDE (
                CALCULATE (
                    countrows( VALUES( Dept_Surveys[SurveyID] )),
                    FILTER ( Dept_Surveys, Dept_Surveys[Survey] = "TOP2" )
                ),
                CALCULATE ( DISTINCTCOUNT ( Dept_Surveys[SurveyID] ) )
            ) * 100
    

    Then:

    Measure = 
    var __Dept = SELECTEDVALUE(Dept_Surveys[Dept])
    var __Perc = [Perc]
    var __Target = calculate(max(Dept_Targets[Target]), Dept_Targets[Dept] = __Dept)
    return
    if(__Perc >= __Target, 1,0)
    

    After That:

    Measure 2 = 
    var __Meettmp =  ADDCOLUMNS(ALL(Dept_Surveys[Dept],Dept_Surveys[MM-YY]), "XX", [Measure])
    var __count = COUNTROWS(__Meettmp)
    var __Meet = SUMX(__Meettmp, [XX])
    return
    DIVIDE(__Meet, __count)
    

    enter image description here