Forum Discussion

VizsWork's avatar
VizsWork
Regular Visitor
7 years ago

Dax Optmisation

Hi All 

Help!!!!! How can I make this dax code faster its too slow and i dont like it

 

HeadCount 12M (ColleagueType) =

VAR MonthSelected = SELECTEDVALUE(Calender[End of Month],EOMONTH(UTCTODAY(),-1))

VAR SummarizedTable =

    CALCULATE(SUMX(SUMMARIZE (

        FACTTABLE,

       FACTTABLE[RepMonth],

        /*FACTTABLE[Employee Type],*/

      "EmployeeDistinctCount",

        CALCULATE (

            DISTINCTCOUNT ( FACTTABLE[Employee Number] ),

            FILTER ( FACTTABLE, FACTTABLE[Name] = "People Operation" ))),

                [EmployeeDistinctCount]),ALLEXCEPT(FACTTABLE,Calender[End of Month]),

DATESBETWEEN(Calender[End of Month],EOMONTH(MonthSelected,-12),MonthSelected))

VAR MonthCount = CALCULATE((COUNTX(SUMMARIZE (

        FACTTABLE,

        FACTTABLE[RepMonth],

        "EmployeeDistinctMonth",

        CALCULATE (

            DISTINCTCOUNT ( FACTTABLE[RepMonth - Copy]),

            FILTER ( FACTTABLE, FACTTABLE[Name] = "People Operation" ))),[EmployeeDistinctMonth])),DATESBETWEEN(Calender[End of Month],EOMONTH(MonthSelected,-12),MonthSelected))

 

  VAR MovingAverage = DIVIDE(SummarizedTable,MonthCount,0)   

Return

MovingAverage

7 Replies

  • pstueven's avatar
    pstueven
    Frequent Visitor

    It might be helpful to tell people what the code actually does or should do. This way not everybody needs to go through it.

    • VizsWork's avatar
      VizsWork
      Regular Visitor

      I want to be able to do a monthly distinct count of employee number for any year and so I can calculate the average employee for the year.
      To archive this, I created a summarized table and grouped it by month with each row contain the distinct employee for the month after which I summed each row to give me the year total

  • PattemManohar's avatar
    PattemManohar
    Community Champion
    VizsWork Could you please throw some sample test data and expected output, so that it will be really helpful to suggest an appropriate solution.
    • VizsWork's avatar
      VizsWork
      Regular Visitor
      RepMonthCount
      Nov-187
      Dec-186
      Jan-197
      Feb-197
      Mar-196
      Average (Sum by month/no of Month)7
        
      Distint Month count5
      Distint Employee count (Incorrect Result)10