Forum Discussion

Jensej's avatar
Jensej
Icon for Helper V rankHelper V
5 years ago
Solved

SUM with filter

Hey guys!

 

I want a chart where i can sum all my sold fruits. If i want to summarice for example Pear i need to scann thruu all artikels and if artikel = Pear and need to get the Amount of the same number. 

 

Can someone help how i can calculate this in a measure? 

 

 

I was trying something like this but it didnt work. 

 

Total sum PEAR= CALCUTE(SUM(Amount1)FILTER(MyTable,MyTable[Artikel1]=Pear))+CALCUTE(SUM(Amount2)FILTER(MyTable,MyTable[Artikel2]=Pear))+CALCUTE(SUM(Amount3)FILTER(MyTable,MyTable[Artikel3]=Pear))+CALCUTE(SUM(Amount4)FILTER(MyTable,MyTable[Artikel4]=Pear))
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Jensej,

    Dax formula not suitable to handle this type of table structure to calculate across multiple fields, it required you to manually add conditions on all the value fields.

    In my opinion, I'd like to suggest you enter to query editor, duplicate raw query and do 'unpivot columns' on the copied query table value fields. Then you can simply write formulas to calculated through these value fields.

    Unpivot columns (Power Query) 

    Regards,

    Xiaoxin Sheng

3 Replies

  • Jensej 

    I use the same method and get the correct result.What's your expected result?

     

    Measure = CALCULATE(sum('Table'[amount1]),FILTER('Table','Table'[ARTIKEL 1]="Pear"))+CALCULATE(SUM('Table'[amount2]),FILTER('Table','Table'[ARTIKEL 2]="Pear"))+CALCULATE(sum('Table'[amount3]),FILTER('Table','Table'[ARTIKEL 3]="Pear"))+CALCULATE(sum('Table'[amount4]),FILTER('Table','Table'[ARTIKEL 4]="Pear"))

     

    btw,your data layout is not good. I suggest you change to something like below.

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Jensej,

    Dax formula not suitable to handle this type of table structure to calculate across multiple fields, it required you to manually add conditions on all the value fields.

    In my opinion, I'd like to suggest you enter to query editor, duplicate raw query and do 'unpivot columns' on the copied query table value fields. Then you can simply write formulas to calculated through these value fields.

    Unpivot columns (Power Query) 

    Regards,

    Xiaoxin Sheng