Forum Discussion

AndreaCami's avatar
AndreaCami
New Member
4 years ago

Failed to make the formula CALCULATE work

This formula worked for me in another report with no problems. I am trying to recycle it in another Power Bi and I get the error message.  "A function "CALCULATE" has been used in a True/False expression that is used as a table filter expression.  This is not allowed."  I have tried using FILTERS but I couldn't get it to work either.

SLA - Communication =

AVERAGEX(VALUES(Dates[Biweek Start]),

Var StartOfBiweek = CALCULATE(SELECTEDVALUE(Dates[Biweek Start]))

Var EndOfBiweek = StartOfBiweek + 13 + 0.999999

RETURN

 

// Open tickets within the biweek: Exclude tickets on Backlog, On Hold or Cancelled at the start of the biweek or during the biweek

VAR tbl_open_tickets =

    VAR Base = CALCULATETABLE(Issues,

                    Issues[Created] < EndOfBiweek,

                    COALESCE(Issues[Closed Date], date(2999,12,31)) >=  StartofBiweek)

 

    VAR TBL = SELECTCOLUMNS(Base,

                "Issue", Issues[Key],

                "Created", Issues[Created],

                "Closed", COALESCE(Issues[Closed Date], date(2999, 12, 31)))

        

// issues_with_evaluation: Universe of tickets that ticket owner should provide visibility within the next two weeks

    VAR issues_with_evaluation =

        ADDCOLUMNS(TBL,

                "Include 1", //To capture issues that were not in Backlog, On Hold, Cancelled before the start of the biweek, i.e. they were already on these status at the start of the biweek

                VAR MaxSequence = CALCULATE(max('History Status'[History Sequence]), 'History Status'[History New Value Start] < StartofBiweek)

                VAR status_at_start_of_biweek =

                                CALCULATE(SELECTEDVALUE('History Status'[History New Value]),

                                            'History Status'[History Sequence] = MaxSequence)

                RETURN

                NOT(status_at_start_of_biweek IN {"Backlog", "On Hold", "Canceled","Completed", "Closed"}))

RETURN

SELECTCOLUMNS(FILTER(issues_with_evaluation, [Include 1] ), "Issues", [Issue])

 

VAR tickets_with_status_change =

             CALCULATETABLE(DISTINCT('History Status'[Key]),

                       'History Status'[History New Value Start] >= StartOfBiweek,

                       'History Status'[History New Value Start] <= EndOfBiweek

                       )

 

VAR tickets_with_comments =

             FILTER(values(Issues[Key]),

             CALCULATE(COUNTROWS(Comments),

               Comments[Comment Created] >= StartofBiweek,

               Comments[Comment Created] <= EndOfBiweek) > 0)

                      

 

VAR open_tickets_count = COUNTROWS(tbl_open_tickets)

VAR Tickets_with_comments_or_change = UNION(tickets_with_status_change, tickets_with_comments)

VAR count_of_tickets_to_include = COUNTROWS(INTERSECT(tbl_open_tickets, Tickets_with_comments_or_change))

RETURN

 

DIVIDE(count_of_tickets_to_include, open_tickets_count))

 

 

6 Replies