Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Dax to create classes based on IF condition

Hello,

 

I'm pretty new in this community and need to solve a Dax problem.

 

The Dax above is my current one but it's too slow:

 

IF(CALCULATE(COUNT(my_table[PDR_POD]),FILTER(my_table, AND(my_table[PDR_POD] = EARLIER(my_table[PDR_POD]),
AND(MONTH(my_table[DATE])=MONTH(EARLIER(my_table[DATE)), YEAR(my_table[DATE])=YEAR(EARLIER(my_table[DATE])) ))))>1 ... 
 
Is there anyone who can help me to write a quicker Dax with the same functionality?
 
Thanks in advance. 
 
 

2 Replies

  • Please learn how to use DAX Studio.  SQLBI.com have great videos on DAX Query tuning.

  • I think it would be better if you use variables

    for example like this:

     

     

    VAR _t1 = MAX(my_table[PDR_POD])
    VAR _MyDate = MAX(my_table[DATE))
    VAR _MyMonth = MONTH(_MyDate)
    VAR _MyYear= YEAR(_MyDate)
    VAR _COUNT = CALCULATE(COUNT(my_table[PDR_POD]),FILTER(my_table, AND(my_table[PDR_POD] = _t1)
    RETURN
    IF(_COUNT,IF(
    AND(MONTH(my_table[DATE])=_MyMonth, YEAR(my_table[DATE])=_MyYear) ))>1...