Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
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
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/
Proud to be a PBI Community Champion
| RepMonth | Count |
| Nov-18 | 7 |
| Dec-18 | 6 |
| Jan-19 | 7 |
| Feb-19 | 7 |
| Mar-19 | 6 |
| Average (Sum by month/no of Month) | 7 |
| Distint Month count | 5 |
| Distint Employee count (Incorrect Result) | 10 |
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 45 | |
| 43 | |
| 39 | |
| 19 | |
| 15 |
| User | Count |
|---|---|
| 68 | |
| 65 | |
| 31 | |
| 28 | |
| 24 |