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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
pg1980
Helper II
Helper II

Sumarize a Cohort Measure

Hi! I have this measure to do a cohort analysis, but i need to sumarize in totals. One option is to use the variable "Monthdiff", changing the value from 1 to 12 and sumarize at the end.

 

Original Measure:

 

Measure Cohort =
VAR MonthDiff =
MAX ( 'table2'[Months] )
VAR MaxOutDate =
CALCULATE ( MAX ( 'Table1'[year-month Out] ), REMOVEFILTERS () )
RETURN
SUMX (
FILTER (
'Table1',
DATEDIFF (
'Table1'[year-month New],
COALESCE ( 'Table1'[year-month Out], MaxOutDate ),
MONTH
) >= MonthDiff
),
'Table1'[Quantity]
) + 0

 

Table1:

  Product       Quantity    year-month New    year-month Out  
AA52023-06 
AA132023-05 
AA12023-07 
AA12023-062023-11
AA12023-062023-10
AA22023-062023-10
AA22023-062023-09
AA422023-062023-09
AA62023-062023-08
AA102023-062023-08
AA532023-062023-07
AA822023-062023-07
AA22023-052023-07
AA12023-052023-06
AA12023-052023-06
AA32023-052023-06
AA42023-052023-06
AA132023-052023-05
AA42023-052023-05
AA42023-052023-10
AA1412023-052023-09
AA452023-052023-09
AA142023-052023-08
AA82023-052023-08
AA3142023-052023-10
AA2252023-052023-11
 
table2=
   GENERATESERIES (0,12,1)
 
Expected Result:

 

  1  2  3  4  5  6  7  8   9  10  11  12 total
  2023-05  775  766  764 742 556 238 13 13 13 13 13 13 3919
  2023-06  204  69  53 9 6 5 5 5 5 5 5 5 376
  2023-07  1  1  1 1 1 1 1 1 1 1 1 1 12
              4307

 

 Row total
2023-05  3919
2023-06  376
2023-07  12
TOTAL  4307
1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @pg1980 

you may try

MeasureCohort =
SUMX (
'table2',
VAR MonthDiff = 'table2'[Months]
VAR MaxOutDate =
CALCULATE ( MAX ( 'Table1'[year-month Out] ), REMOVEFILTERS () )
RETURN
SUMX (
FILTER (
'Table1',
DATEDIFF (
'Table1'[year-month New],
COALESCE ( 'Table1'[year-month Out], MaxOutDate ),
MONTH
) >= MonthDiff
),
'Table1'[Quantity]
) + 0
)

 

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @pg1980 

you may try

MeasureCohort =
SUMX (
'table2',
VAR MonthDiff = 'table2'[Months]
VAR MaxOutDate =
CALCULATE ( MAX ( 'Table1'[year-month Out] ), REMOVEFILTERS () )
RETURN
SUMX (
FILTER (
'Table1',
DATEDIFF (
'Table1'[year-month New],
COALESCE ( 'Table1'[year-month Out], MaxOutDate ),
MONTH
) >= MonthDiff
),
'Table1'[Quantity]
) + 0
)

 

pg1980
Helper II
Helper II

I created one measure for each value but it is not usefull. for example:

Measure Cohort 1 =
VAR MonthDiff = 1
VAR MaxOutDate =
CALCULATE ( MAX ( 'Table1'[year-month Out] ), REMOVEFILTERS () )
RETURN
SUMX (
FILTER (
'Table1',
DATEDIFF (
'Table1'[year-month New],
COALESCE ( 'Table1'[year-month Out], MaxOutDate ),
MONTH
) >= MonthDiff
),
'Table1'[Quantity]
) + 0

Measure Cohort Total= Measure Cohort 1 + Measure Cohort 2 + Measure Cohort 3 + Measure Cohort 4 + Measure Cohort 5 .....

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.