Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
I have a dataset that populates a new row every year for each unique ID. I want to count the number of rows for the preceding 12 months from the current month being viewed in a matrix table. So the Column field is populated with "Date" and these dates are the 1st of every month:
To do this I created a measure with a variable identifying what the oldest month would be:
Solved! Go to Solution.
Thanks Xiaoxin for the response, this looks good.
But I have a measure below that works and did the job 👍
Measure =
VAR EndDate =
EDATE ( MAX ( 'Data'[DATE_MONTH] ), -1 ) + 1 -- adjusts End Date to previous month (so pulls excluding current month)
VAR StartDate =
EDATE ( EndDate, -12 ) + 1 -- sets Start Date 12 months prior to End Date above
VAR TotalActive =
CALCULATE (
COUNTROWS (
FILTER ( 'Data', 'Data'[Status] = "Active" )
),
-- counts rows filtered for Active only in table rather than all rows
DATESBETWEEN (
'Data'[DATE_MONTH],
-- indicates column for dates between
StartDate,
-- Start Date defined above --
EndDate -- End Date defined above --
)
)
VAR TotalInactive =
CALCULATE (
COUNTROWS ( FILTER ( 'Lapse Data', 'Lapse Data'[Status] = "Inactive" ) ),
-- counts rows filtered for all Inactive only in table rather than all rows
DATESBETWEEN (
'Data'[DATE_MONTH],
-- indicates column for dates between
StartDate,
-- Start Date defined above --
EndDate -- End Date defined above --
)
)
RETURN
CALCULATE ( DIVIDE ( TotalActive, TotalInactive, 0 ) )HI @Muzaffar_Ali,
You can try to use the following measure formula if this suitable for your requirement:
formula =
VAR currDate =
MAX ( 'Data'[DATE_MONTH] )
VAR StartofCalc =
CALCULATE (
MAX ( 'Data'[DATE_MONTH] ),
FILTER (
ALLSELECTED ( 'Data' ),
'Data'[DATE_MONTH]
< DATE ( YEAR ( currDate ), MONTH ( currDate ) - 13, DAY ( currDate ) )
)
)
VAR EndofCalc =
CALCULATE (
MAX ( 'Data'[DATE_MONTH] ),
FILTER (
ALLSELECTED ( 'Data' ),
'Data'[DATE_MONTH]
< DATE ( YEAR ( currDate ), MONTH ( currDate ) - 1, DAY ( currDate ) )
)
)
RETURN
CALCULATE (
COUNT ( 'Data'[ID_NBR] ),
FILTER (
ALL ( 'Data' ),
'Data'[DATE_MONTH] >= DATEVALUE ( StartofCalc )
&& 'Data'[DATE_MONTH] <= DATEVALUE ( EndofCalc )
&& 'Data'[Status] = "Active"
)
)
Regards,
Xiaoxin Sheng
Thanks Xiaoxin for the response, this looks good.
But I have a measure below that works and did the job 👍
Measure =
VAR EndDate =
EDATE ( MAX ( 'Data'[DATE_MONTH] ), -1 ) + 1 -- adjusts End Date to previous month (so pulls excluding current month)
VAR StartDate =
EDATE ( EndDate, -12 ) + 1 -- sets Start Date 12 months prior to End Date above
VAR TotalActive =
CALCULATE (
COUNTROWS (
FILTER ( 'Data', 'Data'[Status] = "Active" )
),
-- counts rows filtered for Active only in table rather than all rows
DATESBETWEEN (
'Data'[DATE_MONTH],
-- indicates column for dates between
StartDate,
-- Start Date defined above --
EndDate -- End Date defined above --
)
)
VAR TotalInactive =
CALCULATE (
COUNTROWS ( FILTER ( 'Lapse Data', 'Lapse Data'[Status] = "Inactive" ) ),
-- counts rows filtered for all Inactive only in table rather than all rows
DATESBETWEEN (
'Data'[DATE_MONTH],
-- indicates column for dates between
StartDate,
-- Start Date defined above --
EndDate -- End Date defined above --
)
)
RETURN
CALCULATE ( DIVIDE ( TotalActive, TotalInactive, 0 ) )Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 79 | |
| 38 | |
| 31 | |
| 27 | |
| 27 |