0

I am trying to count all rows in a table in Power BI which uses a Where condition.

I'm not sure what I am doing wrong. Hoping you can help me out. Here is the TSQL Syntax and the results I want. When I execute the DAX query, I get nothing.

I need the DAX statement to work the same and generate the same results. I have been successful at using NOT IN in DAX, but for some reason, I am missing something for the IN clause.

TSQL:

SELECT Closed_Date
     , Closed_By
     , Count(*) CompletedTicket_By_Date
FROM Planning.dbo.IT_Support_Ticket
Where Status In ('Complete', 'Closed', 'Cancelled')
Group By Closed_Date
       , Closed_By

DAX:

Ticket Closed Measure = CALCULATE(COUNTROWS(Fact_IT_Support_Ticket)
,FILTER(Fact_IT_Support_Ticket, Fact_IT_Support_Ticket[Status]="Closed"),
Fact_IT_Support_Ticket[Status]="Complete", 
Fact_IT_Support_Ticket[Status]="Cancelled")

1 Answer 1

1

This can be done using only one filter expression with multiple conditions using the OR operator ||.

Ticket Closed Measure =
CALCULATE (
    COUNTROWS ( Fact_IT_Support_Ticket ),
    FILTER (
        Fact_IT_Support_Ticket,
        Fact_IT_Support_Ticket[Status] = "Closed"
            || Fact_IT_Support_Ticket[Status] = "Complete"
            || Fact_IT_Support_Ticket[Status] = "Cancelled"
    )
)

As said in documentation the second argument of the filter function is a boolean expression that is evaluated per row. Note the expression above evaluates if every value in the Status column is Complete, Closed, Cancelled. The COUNTROWS function counts only the filtered rows in the given context.

REFERENCE

I've not tested the solution but it should work, let me know if this works for you.

1
  • Thanks for the help. Exactly what I needed!!
    – Neeru
    Commented Aug 29, 2016 at 4:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.