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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Regnbagar1
Helper I
Helper I

Measure doesn't work with filters

Hi!

I have created a measure that should calculate the SUM of the last three months. The measure only works for one of the countries when I use a dimension table as filter. In this case the measure works for country 1 but no other country. 

Skärmavbild 2022-04-08 kl. 10.26.45.png

Skärmavbild 2022-04-08 kl. 10.26.17.png


The relations between the dimension tables are correct (one to many relationships). Does any one know what I'am doing wrong or if there is any other solution to this problem. 

Measure:

Calculation Last 3 month =
VAR calculation_l3m = CALCULATE([VALUE]),
DATESINPERIOD(Date_table[YearMonth], LASTDATE(DATEADD(Date_table[YearMonth], 0, MONTH)), -3, MONTH)
)

RETURN calculation_l3m


Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Regnbagar1 ,

 

Sorry for my late reply.

You could try the following to create a column:

Column = 
var _last3months=EOMONTH([yearmonth],-3)
return CALCULATE(SUM('Table'[Value]),FILTER('Table',[country]=EARLIER('Table'[country]) && [yearmonth]>_last3months &&[yearmonth]<= EARLIER('Table'[yearmonth])))

Eyelyn9_0-1650438783340.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hi @Regnbagar1 ,

 

Sorry for my late reply.

You could try the following to create a column:

Column = 
var _last3months=EOMONTH([yearmonth],-3)
return CALCULATE(SUM('Table'[Value]),FILTER('Table',[country]=EARLIER('Table'[country]) && [yearmonth]>_last3months &&[yearmonth]<= EARLIER('Table'[yearmonth])))

Eyelyn9_0-1650438783340.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

It worked, thank you so much! 🙂 

Anonymous
Not applicable

Hi @Regnbagar1 ,

 

Mine is a measure. Do you want a measure or a column?

 

Best Regards,
Eyelyn Qin

Ah thank you!

Preferably as a calculated column. But 'll try this measure. 🙂

Anonymous
Not applicable

Hi @Regnbagar1 ,

 

Please try:

Sum of Last 3 Months =
VAR _last3months =
    EOMONTH ( MAX ( 'Table'[yearmonth] ), -3 )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            [country] = MAX ( 'Table'[country] )
                && [yearmonth] > _last3months
                && [yearmonth] <= MAX ( 'Table'[yearmonth] )
        )
    )

Output:

Eyelyn9_1-1649821224496.png

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

If I try to do exactly as you did I get this result instead.

Skärmavbild 2022-04-13 kl. 15.14.36.png



amitchandak
Super User
Super User

@Regnbagar1 , Hope year month is date, prefer use date of date table

 

Calculation Last 3 month =
VAR calculation_l3m = CALCULATE([VALUE]),
DATESINPERIOD(Date_table[Date], LASTDATE(Date_table[Date]), -3, MONTH)
)

RETURN calculation_l3m

 

Rolling Months Formula: https://youtu.be/GS5O4G81fww

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi,

yearmonth is a date column. And when I use Date_table[Date] I get this error message.

Skärmavbild 2022-04-08 kl. 10.59.35.png

 

I have the same problem if I try to do it as a calculated column. As mentioned before I would like to sum the value last three months. So that the value in 2021-06 would be 149 + 214,23 + 229 = 592.23

Skärmavbild 2022-04-08 kl. 14.54.24.png

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors