Forum Discussion

GreenKnight1294's avatar
GreenKnight1294
Frequent Visitor
3 years ago
Solved

SUMIFS Equivalent to Check for Row Value

Good evening.

 

I'm trying to build a SUMIFS equivalent formula that checks the value of a given row and sums the values in a column that match the values of that row. I wrote the following formula:

 

=CALCULATE(SUM('TABLE'[Quantity]),

FILTER('TABLE',[Registry]="2290"),

FILTER('TABLE',[Type]="Print")

)

 

I would really appreciate some help coding a version of it that checks the value of the current row rather than a fixed constant of "2290".

 

Thank you!

  • Ritaf1983's avatar
    Ritaf1983
    3 years ago

    Hi GreenKnight1294  on this table my solution works.

    I can't figure out what the problem is.

    "Fix" a cell in POWER BI is not possible because of the logic it uses

    Rather than working at the cell level, it works at the column level.

    It's a game where you release filters and apply filters in a context.

    Sumifs in the context of multiple conditions is like I showed calculate ([measure], condition A && condition B etc..)

     

    Unfortunately, I don't know how to help beyond that...

  • pls try this

    Column = 
    VAR t1 = [Registry]
    VAR t2 = [Type]
    VAR _Results = SUMX(FILTER(ALL('Table'),'Table'[Registry]=t1&&'Table'[Type]=t2),[QTY])
    RETURN
    _Results

10 Replies

  • pls try this

    Column = 
    VAR t1 = [Registry]
    VAR t2 = [Type]
    VAR _Results = SUMX(FILTER(ALL('Table'),'Table'[Registry]=t1&&'Table'[Type]=t2),[QTY])
    RETURN
    _Results

    • GreenKnight1294's avatar
      GreenKnight1294
      Frequent Visitor

      Sir, you're a wizard. I wish I could give you more than just a thumbs up.

       

  • Hi GreenKnight1294 
    Try :

    =CALCULATE(SUM('TABLE'[Quantity]),FILTER('TABLE',[Registry]="2290"&& [Type]="Print"),

    )

     

    Make sure that data type of registry column is text :

     

    Link to a sample file 

    If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

    • GreenKnight1294's avatar
      GreenKnight1294
      Frequent Visitor

      Hey Rita,

       

      Thank you so much for taking your time to check this.

       

      This isn't exactly what I'm looking for.

       

      Would it be possible to have these values calculated in every row of the table? Per your example I want the following to show in PowerPivot, so that the values that share the same filters will repeat and show the same sum.

      Thank you.

       

      • Ritaf1983's avatar
        Ritaf1983
        Icon for Super User rankSuper User

        Hi GreenKnight1294 
        Unfortunately, I don't know how it works in power pivot.
        In power bi to achieve your goal you can add a calculated column with Dax formula :

        test = if([Registry]="2290"&&'Table (2)'[Type]="print",CALCULATE(sum('Table (2)'[QTY]),ALLEXCEPT('Table (2)','Table (2)'[Registry],'Table (2)'[Type])),'Table (2)'[QTY]).

        I also updated a sample file .
        If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

  • Thank you, Rita.

     

    Here's a similar table to what I showed before with the desired result.

     

    The fourth column has the following formula in Excel:

    =SUMIFS($A$2:$A$20,$B$2:$B$20,B2,$C$2:$C$20,C2)

     

    QTYRegistryTypeSUM
    22290print40
    82290print40
    102290print40
    122291print27
    132291print27
    22291print27
    02291print27
    32292print29
    82292print29
    72292print29
    62292print29
    52292print29
    92290print40
    112290print40
    162294print43
    192294print43
    52294print43
    32294print43

     

    The most important part is that all the numbers that share the same registry value are added together.