Forum Discussion

srl01's avatar
srl01
Icon for Helper II rankHelper II
9 years ago
Solved

Sumifs in DAX, using a value in the same row as filter condition

 

I am looking to do an analysis on retail data structured with one line per item sold, and unique BasketIDs for each basket of items.

Would like to "score" each basket by the combination of brands in the basket (i.e. all item purchases found elsewhere in the table with the same BasketID), and apply that score to each item.

 

First I have an item / brand / score master Table2

ItemBrandScore
ABCBrandA1
DEFBrandB10
GHIBrandC100
JKLBrandD1000

 

And then the calcs I want, with Excel functions.

(Note the Brand column below is superfluous, but included for clarity)

 

(raw data)(raw data)=VLOOKUP([@Item],Table2,2,FALSE)=VLOOKUP([@Item],Table2,3,FALSE)=SUMIFS([ItemBrandScore],[BasketID],[@BasketID])
BasketIDItemBrandItemBrandScoreBasketBrandScore
1ABCBrandA1111
1DEFBrandB10111
1GHIBrandC100111
2ABCBrandA111
2DEFBrandB1011
3GHIBrandC100100
4DEFBrandB101110
4GHIBrandC1001110
4JKLBrandD10001110

 

So for example, basket 1 contains three items, one each from BrandA, BrandB and BrandC.

These have Brand scores of 1,10,100 respectively. So the Score for basket 1 is 1+10+100 = 111.

 

 

How can I replicate this functionality - specifically the SUMIFS part -using DAX, assuming with tables structured the same way?

 

  • Hi srl01

     

    Ok apologies for sometimes going around in circles because I am trying to understand your requirements.

     

    What I would then do is go into the Query Editor and copy the existing table (Source Table) where you have the details. Then in this second table (Brand Group) I would then look to get the Band Scoring per Basket ID. This could possibly be done with the Group By.

     

    After which I would then merge my first table (Source Table) with my second table (Brand Group) on the Basket ID using a left join.

    What this would then do is to take the Band Total and put it across all the rows in your first table (Source Table).

     

    And then from there you could easily create a conditional column based on the Band Score.

     

    That would then allow you to have all your data in columns in your dataset.