Forum Discussion

tenbrooks10's avatar
tenbrooks10
New Member
3 years ago
Solved

Calculation group does not properly aggregate measures created using DIVIDE()

Calculation groups in Analysis Services (AS) are incredibly powerful for doing quick rolling 12 month (R12) type aggregations to smooth trend data (among many other cool things that calculation group...
  • KeithDunn's avatar
    3 years ago

    I finally solved it on my own. What I was looking for was a way to get DAX to follow the default aggregation for the measure in the database rather than simply summing everything. I finally realized that CALCULATE does this if there is no instruction to do otherwise. The correct code for a rolling 12 where the 12-month period ends with the previous month (to leave out a partial current month) is:

     

    CALCULATE (
    SELECTEDMEASURE(),
    PARALLELPERIOD(DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -12, MONTH ), -1, MONTH)
    )

     

    If you want to include the current month in the 12-month period, just take out the PARALLELPERIOD:

     

    CALCULATE (
    SELECTEDMEASURE(),
    DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -12, MONTH )
    )

     

    I am not sure why the original developer was forcing a SUMX only in the R12 calculation group item but it may have been due to an earlier bug. Anyway it works fine now. 

     

    Thanks!