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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Madumi
Regular Visitor

Filter by previous month (January minus one not working as expected)

I wondered if someone could point me in the right direction. I am trying to obtain the sum of last month's project values using the following measure:

 

Previous Month = var current_month= MONTH(TODAY()) return CALCULATE(SUM(cr6a2_Project[Project Value]),FILTER(cr6a2_Project,MONTH(cr6a2_Project[cr6a2_approxclosedate])=current_month -1))

 

 Entity is cr6a2_Project, date field is cr6a2_approxclosedate, and value field in $ is Project Value

Do I also need to specify current year?

And how would I specify December of the previous year, when the current date is January?

Thanks!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Madumi 

 

You can try the measure this way:

Previous Month = 
var prev_month= FORMAT(EOMONTH(TODAY(),-1), "yyyymm") return 
CALCULATE(
    SUM(cr6a2_Project[Project Value]),
    FILTER(
        cr6a2_Project,
        FORMAT(cr6a2_Project[cr6a2_approxclosedate], "yyyymm")=prev_month
    )
)

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@Madumi 

 

You can try the measure this way:

Previous Month = 
var prev_month= FORMAT(EOMONTH(TODAY(),-1), "yyyymm") return 
CALCULATE(
    SUM(cr6a2_Project[Project Value]),
    FILTER(
        cr6a2_Project,
        FORMAT(cr6a2_Project[cr6a2_approxclosedate], "yyyymm")=prev_month
    )
)

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

littlemojopuppy
Community Champion
Community Champion

Going to suggest you try this instead...

Current Month = SUM(cr6a2_Project[Project Value])

Previous Month = 
	CALCULATE(
		[Current Month],
		PREVIOUSMONTH('Calendar'[Date])
	)

Previous Month Alternative = 
	CALCULATE(
		SUM(cr6a2_Project[Project Value]),
		PREVIOUSMONTH('Calendar'[Date])
	)

This assumes you have a date table named "Calendar" and it is marked accordingly.

 

The measure [Current Month] calculates the Project Value in the current month.  The [Previous Month] measure uses time intelligence to shift the filter context to one month earlier.  Makes it much simpler to accomplish.  Or you can use just the [Previous Month Alternative] instead and still rely on time intelligence.

 

Hope this helps!  🙂

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.