Forum Discussion

AJPF's avatar
AJPF
Icon for Helper I rankHelper I
5 years ago

A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expre

I realise that there are a few posts with similar titles but I've looked through all of them I and still don't have my answer! 

 

I am trying to write a new measure which will calculate late returns, i.e.: "calculate sum of full returns where late". 

 

So my DAX formula is: 

 
Late Return = calculate(sum(Compliance[Full return]), [No. of days late] > 1)
 
where "No. of days late" is already defined as: 
 
No. of days late = if([Deadline] >= today(), blank(), if(isblank(selectedvalue(Compliance[Date Returned])), datediff([Deadline], today(), DAY), datediff([Deadline], selectedvalue(Compliance[Date Returned]), DAY)))
 
What am I doing wrong? 
 
Please keep your answers simple as I am only seven weeks into my Power BI journey! 
 

5 Replies

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    This is an old post but explains the error and fix.  

    https://powerpivotpro.com/2012/06/filter-when-why-how-to-use-it/

     

    You need to use FILTER in your CALCULATE for this more complex evaluation.  For example,

    Late Return = calculate(sum(Compliance[Full return]), FILTER(VALUES(Compliance[Column), [No. of days late] > 1))

     

    You need to use VALUES or ALL, or just filter the whole Compliance table, and that measure will be evaluated on each row so that the table can be filtered to >1.


    Regards,

    Pat

     

    • AJPF's avatar
      AJPF
      Icon for Helper I rankHelper I

      I think I understand it now.  My new formula is: 

       

      Late Return = calculate(sum(Compliance[Full return]), filter(Metrics, [No. of days late] > 1))
       
      but this doesn't work because I still get ALL full returns.  The filter element isn't working. 
       
      Where you have written: 
       
      Late Return = calculate(sum(Compliance[Full return]), FILTER(VALUES(Compliance[Column], [No. of days late] > 1))
       
      what exactly is "Column"? 
       
      • mahoneypat's avatar
        mahoneypat
        Icon for Microsoft Employee rankMicrosoft Employee

        Column is any one of your columns, or you can make a table expression with multiple columns.  Whatever the entity is for which the {No of Days Late] measure should be evaluated is what you need to put there.  If you explain further and show your example/mock data, a specific expression can be suggested.

        Regards,

        Pat