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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Help with filter inside iterator measure

Hi,
I have the following measure and works fine for month "8" or any other given month (changing the number on calculate filter), but I need make a new measure that instead of the given month, show the last available month so I don't have to change it manually every month.
 
Measure for month 8 = SUMX(
ADDCOLUMNS(
SUMMARIZE(
'DB asignaciones'
, 'DB asignaciones'[Month]
, 'DB asignaciones'[RBD]
, 'DB asignaciones'[YEAR]
)
, "PP" , CALCULATE( MAX( 'DB asignaciones'[Poblacion Potencial RBD]),'DB asignaciones'[Month]=8)
)
, [PP])
 
any help would be greatly appreciated!
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I think it makes more sense to filter before summarizing instead of after.

 

Try something like this:

Measure for last available month =
VAR LastAvailableMonth = MAX ( 'DB asignaciones'[Month] )
VAR LastAvailableYear  = MAX ( 'DB asignaciones'[YEAR] )
RETURN
    SUMX (
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER (
                    'DB asignaciones',
                    'DB asignaciones'[Month] = LastAvailableMonth &&
                    'DB asignaciones'[YEAR]  = LastAvailableYear
                ),
                'DB asignaciones'[RBD]
            ),
            "PP", CALCULATE ( MAX ( 'DB asignaciones'[Poblacion Potencial RBD] ) )
        ),
        [PP]
    )

 

You can probably simplify it further like this:

Measure for last available month =
VAR LastAvailableMonth = MAX ( 'DB asignaciones'[Month] )
VAR LastAvailableYear  = MAX ( 'DB asignaciones'[YEAR] )
RETURN
    SUMX (
        CALCULATETABLE (
            VALUES ( 'DB asignaciones'[RBD] ),
            KEEPFILTERS ( 'DB asignaciones'[Month] = LastAvailableMonth ),
            KEEPFILTERS ( 'DB asignaciones'[YEAR]  = LastAvailableYear )
        ),
        CALCULATE ( MAX ( 'DB asignaciones'[Poblacion Potencial RBD] ) )
    )

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

I think it makes more sense to filter before summarizing instead of after.

 

Try something like this:

Measure for last available month =
VAR LastAvailableMonth = MAX ( 'DB asignaciones'[Month] )
VAR LastAvailableYear  = MAX ( 'DB asignaciones'[YEAR] )
RETURN
    SUMX (
        ADDCOLUMNS (
            SUMMARIZE (
                FILTER (
                    'DB asignaciones',
                    'DB asignaciones'[Month] = LastAvailableMonth &&
                    'DB asignaciones'[YEAR]  = LastAvailableYear
                ),
                'DB asignaciones'[RBD]
            ),
            "PP", CALCULATE ( MAX ( 'DB asignaciones'[Poblacion Potencial RBD] ) )
        ),
        [PP]
    )

 

You can probably simplify it further like this:

Measure for last available month =
VAR LastAvailableMonth = MAX ( 'DB asignaciones'[Month] )
VAR LastAvailableYear  = MAX ( 'DB asignaciones'[YEAR] )
RETURN
    SUMX (
        CALCULATETABLE (
            VALUES ( 'DB asignaciones'[RBD] ),
            KEEPFILTERS ( 'DB asignaciones'[Month] = LastAvailableMonth ),
            KEEPFILTERS ( 'DB asignaciones'[YEAR]  = LastAvailableYear )
        ),
        CALCULATE ( MAX ( 'DB asignaciones'[Poblacion Potencial RBD] ) )
    )

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.