Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Subtotal based on condition from other rows

Hello everyone,

 

I have the following example table, where Brands 1 and 2 are from my company:

StoreBrandValue
S1B1500
S1Other285
S2B2108
S2Other508
S3Other251
S4B1208
S4B2999

 

What I would like to calculate is the total value of the stores that my brands are present, that is, the total value of the store (my brands + others).

For exemple, considering Brand1 I should see: (500 + 285 + 208 + 999) = 1992.

considering Brand 2 I should see: (108 + 508 + 208 + 999) = 1823.

 

My output should be a table that look like this:

B11992
B21823
Total2608
  • Anonymous Maybe:

    Measure =
      VAR __Brand = MAX('Table'[Brand])
      VAR __Stores = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[Brand]=__Brand),"Store",[Store]))
    RETURN
      SUMX(FILTER(ALL('Table'),[Store] IN __Stores),[Value])

2 Replies

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

    Anonymous Maybe:

    Measure =
      VAR __Brand = MAX('Table'[Brand])
      VAR __Stores = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[Brand]=__Brand),"Store",[Store]))
    RETURN
      SUMX(FILTER(ALL('Table'),[Store] IN __Stores),[Value])
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Greg!

      I had to tweak your solution a little bit but it worked!

       

      Your idea of creating a list of the stores that I had to consider/evaluate was genius. I wasn't aware of the "IN" operator.