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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.