Forum Discussion

ShrikantKhanna's avatar
9 years ago
Solved

Solution for COUNTIFS

Hi, I am trying to achieve a simple COUNTIFS solution in Power BI. I have read multiple messages but none of them are working out for me. I am trying to add a new column in my table and calculate th...
  • Amratya's avatar
    9 years ago

    Please give this a try:

    Column D =
    CALCULATE (
        COUNTROWS ( 'TableName' ),
        ALLEXCEPT (
            'TableName',
            'TableName'[Team Name],
            'TableName'[Week #],
            'TableName'[Year]
        )
    )

  • v-huizhn-msft's avatar
    v-huizhn-msft
    9 years ago

    Hi ShrikantKhanna,

    You can use EARLIER function when you create calculated column. I used FILTER(Table5,Table5[Team Name]=EARLIER(Table5[Team Name])), which mean it will return the subtable with same Team name. Filter is compared to the criteria. Then I add multiple filters, so the formula will count [Team Name] where satisfy Filter1, Filter2, Filter3 and so on. 

    Result = CALCULATE(COUNTA(Table5[Team Name]),FILTER(Table5,Table5[Team Name]=EARLIER(Table5[Team Name])),FILTER(Table5,Table5[Week#]=EARLIER(Table5[Week#])),FILTER(Table5,Table5[Year]=EARLIER(Table5[Year])))


    Please review expected result in the following screenshot.

     

    If you have other issues, please feel free to ask.

    Best Regards,
    Angelia