Forum Discussion

ashishtele's avatar
ashishtele
Frequent Visitor
10 years ago
Solved

Percentage calculation for multiple months

Hello,   I have data table with three columns Employee, month ,B and C. I have to calculate B/C (B divide by C) for each employee and month. I have created new coulmn = B/C and it is working fine f...
  • greggyb's avatar
    greggyb
    10 years ago

    The following measures achieve what you want.

     

    SumB =
    SUM( 'MyTable'[B] )     // It's considered best practice to always use
                                        // fully qualified column names in Table[Column]
                                        // format.
    
    SumC =
    SUM( 'MyTable[C] )
    
    BoverC =
    DIVIDE( [SumB], [SumC] )      // It is considered best practice to use
                                                    // only the measure name (without table
                                                    // reference) when referring to measures

    CALCULATE() would only be necessary if you want to write code to manipulate the filter context for the measure.

     

    If you use BoverC in a report now, you can put it in the Value(s) area of a visualization. Putting months on the axis would give you BoverC by month. If you put BoverC in a visualization alone and use month as a slicer you will see the appropriate behavior when you select a subset of months.