Forum Discussion

WLFRD's avatar
WLFRD
Icon for Helper III rankHelper III
5 years ago
Solved

SUM values filtered by another column

Hello,

 

I have been using Power BI for some time but I now run into an issue I don't know how to solve yet.

 

So I have a table like this:

CodeOHNOH
12510
12510
12510
12510
12501
12501
12610
12610
12601
12710
12710
12710
12710
12801
12801

 

And I would like to count the OH 1's and NOH 1's per code. The end result would look like this:

CodeOHNOH
12542
12621
12740
12802

 

I have tried several DAX functions and some standard options which Power BI has. Up until now, I was not able to get the result I would like to see.

 

Maybe someone can help me out with this issue.

 

Thanks in advance.

 

Regards,

Wilfred

  • Count OH=

    Hi WLFRD 

    VAR _Code = SELECTEDVALUE(TABLE[CODE])

    VAR _RESULT = CALCULATE(COUNT(TABLE[OH]), TABLE[CODE] = _Code)

    RETURN

    _RESULT

     

    do the same for NOH

    But i think you want to see the SUM and not the COUNT. if so replace Count by SUM.

     

     

4 Replies

  • aj1973's avatar
    aj1973
    Icon for Community Champion rankCommunity Champion

    Count OH=

    Hi WLFRD 

    VAR _Code = SELECTEDVALUE(TABLE[CODE])

    VAR _RESULT = CALCULATE(COUNT(TABLE[OH]), TABLE[CODE] = _Code)

    RETURN

    _RESULT

     

    do the same for NOH

    But i think you want to see the SUM and not the COUNT. if so replace Count by SUM.

     

     

  • aj1973's avatar
    aj1973
    Icon for Community Champion rankCommunity Champion

    If all good please mark the thread as solved for the rest of the community.

  • For some reason the provided possible solution didn't solve the problem. What I've done is, use the standard Count and Distinct Count option in Power BI. 

    • aj1973's avatar
      aj1973
      Icon for Community Champion rankCommunity Champion

      Did you use SUM instead?

      Can you share your file?

      Is your porblem solved?