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
steph_io
Advocate II
Advocate II

direct query previous month

 

With Direct Query, some built in functions are no longer working.

I need a measure for previous month, previous quarter, previous year... to calcualte variance and growth. These measure should consider the previous month, year that falls outside of the slicer filter as well. 

 

Here are my formulas for Current Month CM and Priort Month PM:

Trans Accounts CM = CALCULATE([Trans Accounts],FILTER(ALL(DimDate), DimDate[FirstDayOfMonth] = max(DimDate[FirstDayOfMonth])))
Trans Accounts PM = CALCULATE([Trans Accounts CM],DATEADD(DimDate[FirstDayOfMonth],-1, MONTH))

 

How do I change the PM formula to consider the previous month that falls before the date slicer?

 

 

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @steph_io,

 

If I understand you correctly, you should be able to follow steps below to get your expected result. Smiley Happy

 

1. Use the formula below to add new calculate column in your DimDate table.

YearMonth =
YEAR ( DimDate[FirstDayOfMonth] ) * 12
    + MONTH ( DimDate[FirstDayOfMonth] )

2. Then you should be able use the formula below to calculate the Trans Accounts PM.

Trans Accounts PM =
CALCULATE (
    [Trans Accounts],
    FILTER ( ALL ( DimDate ), DimDate[YearMonth] = MAX ( DimDate[YearMonth] - 1 ) )
)

 

Regards

View solution in original post

2 REPLIES 2
v-ljerr-msft
Employee
Employee

Hi @steph_io,

 

If I understand you correctly, you should be able to follow steps below to get your expected result. Smiley Happy

 

1. Use the formula below to add new calculate column in your DimDate table.

YearMonth =
YEAR ( DimDate[FirstDayOfMonth] ) * 12
    + MONTH ( DimDate[FirstDayOfMonth] )

2. Then you should be able use the formula below to calculate the Trans Accounts PM.

Trans Accounts PM =
CALCULATE (
    [Trans Accounts],
    FILTER ( ALL ( DimDate ), DimDate[YearMonth] = MAX ( DimDate[YearMonth] - 1 ) )
)

 

Regards

This also resolves the issue I had with my calculations not looking at prior month when it fell in prior year. My formula wasn't working for each january. Thank you! 

 

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.