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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Kurt4597
Helper I
Helper I

Previous Month Filtering

Hello All,

 

I have been stuck on this issue for a few hours and really can't seem to fix it. Any help would be greatly appreciated. 

DateDim Table

Kurt4597_4-1662053968964.png

 

 

Deals Table

Kurt4597_5-1662053988156.png

 

 

I have a measure called "Average Cost" which is the Total Cost / Total number of deals. This measure works as expected and can be filtered by whichever month has been selected. My issue is when I try to create a measure for Average cost Last month.  To do this I have created a measure called PreviousDate

Kurt4597_2-1662053183450.png

PreviousDate measure - This value is generated depending on whatever is selected in the filter. For example I have currently selected May 2022, so the measure shows 2022-04 

 

I am then trying to filter the Deals table, where the YearMonth Column = Previous Month measure. See below 

Kurt4597_3-1662053433138.png

 

What I have tried 

I did initially try the formula 
Average Cost Last Month = CALCULATE([Average Cost], DateDim[YearMonth] = [PreviousDate])

But I am Given This error 
Kurt4597_0-1662111510236.png

 

After researching this, I believe the work around was to use all function & filter function, so I produced this 

Average Cost Last Month =

CALCULATE([Average Cost],

all('DateDim'[YearMonth]), filter(DateDim, DateDim[YearMonth] = [PreviousDate])

)

 

But this just returns a blank value. I need the AVERAGE COST MEASURE but only for values that are in the PREVIOUSMONTH to the current month selected

Any help would be massively appreciated!
 
-

 




 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Could you please try something like below and please check whether it suits your requirement?

 

Average Cost Last Month =
VAR _prevdate = [PreviousDate]
RETURN
    CALCULATE (
        [Average Cost],
        FILTER ( ALL ( DateDim ), DateDim[YearMonth] = _prevdate )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

Could you please try something like below and please check whether it suits your requirement?

 

Average Cost Last Month =
VAR _prevdate = [PreviousDate]
RETURN
    CALCULATE (
        [Average Cost],
        FILTER ( ALL ( DateDim ), DateDim[YearMonth] = _prevdate )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Worked great thank you!

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.