Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
craigdormire
Frequent Visitor

DAX Cumulative sum by Month/Quarter/Year but only include contributing months

I need help modifying/creating a measure to correctly aggregate so that when monthly results are rolled up to quarterly and yearly, only values from aged months contribute to the total.  What rolls up to the total should be controlled by the age of the contributing months.  

Here's the current DAX measure:

Units (Cuml. by Age) =
var Max_Age = max('Monthly_Data'[Age])
return
CALCULATE(
[Units (Non-Cuml.)],
    'Monthly_Data'[Age]<=Max_Age
 )


This measure works for the Cumulative Sum at the monthly level, but as you can see below, because of the <=Max_Age logic, the quarterly and yearly totals are adding all prior months, not just the vintages that are aged to that point. 

craigdormire_0-1697826203748.png


So, you can see that January is the only "fully aged" month, so that should be the only value "contributing" to Q1 and for 2023 at Age '8'.  Basically, I need it to sum up the column:

-  at point 8, the monthly, Q1 and 2023 cumulative total should all be '366'

- at point 7, the Q1 and 2023 totals should be '533'

- at point 5, the Q1 total should be '313' but the 2023 total should be '444' (Q1 + April) 

Since I haven't gotten this approach to work, I've thought about a 2 step approach, where I calculate the cumulative sum/running total locked in at the monthly level by age, then just sum the monthly cumulative value by quarter and year at each age.  But I haven't really figured out how to make this concept work either.

 

Thanks for any help/ideas you can provide!

1 ACCEPTED SOLUTION
craigdormire
Frequent Visitor

I believe my internal company PBI User Group has found a solution.  See below:

Units (Cuml. by Age) =

var Max_Age = max('Monthly_Data'[Age])

var Valid_Months = CALCULATETABLE (

  DISTINCT ( 'Monthly_Data'[Month] ),

  FILTER ( 'Monthly_Data', 'Monthly_Data'[Age] = Max_Age )

)

return

CALCULATE(

  [Units (Non-Cuml.)],

  'Monthly_Data'[Age]<=Max_Age,

  'Monthly_Data'[Month] IN Valid_Months

)

 

Thanks to anyone/everyone out there that took time to look at this with me!  Consider this one SOLVED!

View solution in original post

3 REPLIES 3
craigdormire
Frequent Visitor

I believe my internal company PBI User Group has found a solution.  See below:

Units (Cuml. by Age) =

var Max_Age = max('Monthly_Data'[Age])

var Valid_Months = CALCULATETABLE (

  DISTINCT ( 'Monthly_Data'[Month] ),

  FILTER ( 'Monthly_Data', 'Monthly_Data'[Age] = Max_Age )

)

return

CALCULATE(

  [Units (Non-Cuml.)],

  'Monthly_Data'[Age]<=Max_Age,

  'Monthly_Data'[Month] IN Valid_Months

)

 

Thanks to anyone/everyone out there that took time to look at this with me!  Consider this one SOLVED!

littlemojopuppy
Community Champion
Community Champion

@craigdormire at first glance I would think you would also need a variable to determine fully aged months to include in your CALCULATE() statement.  Difficult to determine what the DAX should be without sample data...can you provide some?

YearQuarterMonthUnits - Non-Cuml.MSF
2023Qtr 1January00
2023Qtr 1January01
2023Qtr 1January22
2023Qtr 1January83
2023Qtr 1January224
2023Qtr 1January735
2023Qtr 1January756
2023Qtr 1January737
2023Qtr 1January1138
2023Qtr 1February00
2023Qtr 1February01
2023Qtr 1February22
2023Qtr 1February123
2023Qtr 1February204
2023Qtr 1February705
2023Qtr 1February856
2023Qtr 1February917
2023Qtr 1March00
2023Qtr 1March01
2023Qtr 1March62
2023Qtr 1March83
2023Qtr 1March214
2023Qtr 1March1195
2023Qtr 1March1356
2023Qtr 2April00
2023Qtr 2April21
2023Qtr 2April12
2023Qtr 2April63
2023Qtr 2April224
2023Qtr 2April1005
2023Qtr 2May00
2023Qtr 2May01
2023Qtr 2May22
2023Qtr 2May93
2023Qtr 2May344
2023Qtr 2June00
2023Qtr 2June01
2023Qtr 2June62
2023Qtr 2June163
2023Qtr 3July00
2023Qtr 3July01
2023Qtr 3July22
2023Qtr 3August00
2023Qtr 3August01
2023Qtr 3September00

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.