Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
VizsWork
Regular Visitor

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 7
v-frfei-msft
Community Support
Community Support

Hi @VizsWork ,

 

We can use GROUPBY instead of  SUMMARIZE. Please refer to the third - party blog.

https://www.sqlbi.com/articles/nested-grouping-using-groupby-vs-summarize/

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
PattemManohar
Community Champion
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.




Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Sample.PNG

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

 

 

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.

thanks your reply

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

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.