Forum Discussion

iraskop's avatar
iraskop
Frequent Visitor
10 years ago
Solved

Calculating totals within dimension

Searching and searching for this answer on the forum and I'm baffled that I don't see it.   Lets say I have: Dim1   Dim2   Meas1  [Pct Meas1/Dim1] A         X         4            4/(4+5)=4/9 A ...
  • greggyb's avatar
    greggyb
    10 years ago

    kazlik, that would work in a Calculated Column, but not as a Measure. There is no row context in a Measure for EARLIER() to refer to.

     

    The following should work as a measure (depends on [Meas1] evaluating correctly at the subtotal level - we can address this if it doesn't):

     

    // DAX
    // Measure
    Meas1 =
    <your Meas1 definition>
    
    //Measure
    Meas1GroupTotal =
    CALCULATE(
        [Meas1]
        ,ALLEXCEPT( 'Dim1Table', 'Dim1Table'[Dim1] )
    )
    
    Meas2 =
    DIVIDE( [Meas1], [Meas1GroupTotal] )

    ALLEXCEPT() clears all context except for that in the named column(s) in arguments 2-N. It has the benefit of clearing filter or row context, and therefore works equally well in a Measure or Calculated Column.