Forum Discussion
markus_zhang
Advocate III
7 years agoHow can I further optimize this DAX formula?
Hi experts, I have a table with 12 million rows and two columns: email | logins Basically it's a table of login records for each account (email) between 2018-10-17 and 2019-01-16. ...
- 7 years ago
Hi markus_zhang
Unless I'm missing something, what your code does in a slightly convoluted manner is count how many users (emails) have logged in on the date selected in the slicer or any of the previous [ActiveThreshold] days. If so, you can simplify the code a whole lot:
Measure =
IF (
ISFILTERED ( WeekMatrix[Date] ),
VAR _SelectedDate = SELECTEDVALUE ( WeekMatrix[Date] )
RETURN
CALCULATE (
DISTINCTCOUNT ( NTKLogin[email] ),
NTKLogin[logins] <= _SelectedDate, NTKLogin[logins] >= _SelectedDate - [ActiveThreshold]
),
ERROR ( "This measure can only be evaluated under the filter context of WeekMatrix[Date]" )
)
markus_zhang
Advocate III
7 years agoHi Greg_Deckler thanks, it's a bit embarassing but I'm not familiar with SUMMARIZE(), guess it's time to learn it for real!
Greg_Deckler
Community Champion
7 years agoIt's one of my favorites.
https://docs.microsoft.com/en-us/dax/summarize-function-dax
However, my understanding is that SUMMARIZE is sort of being phased out with the replacement being SUMMARIZECOLUMNS:
https://docs.microsoft.com/en-us/dax/summarizecolumns-function-dax
If you know SQL, think GROUP BY