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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
shihwenwu
Frequent Visitor

previous month and column filter

Hi,

 

I want to create a new column "pre_ops", which get "order product sales" of the previous month (by Yr_month) based on "account".

 

DAX_previous_month.PNG

 

Here is my solution:

pre_ops = CALCULATE(MAX(Month_over_Month[order_product_sales]),FILTER(Month_over_Month,Month_over_Month[account]=EARLIER(Month_over_Month[account])),PREVIOUSMONTH(Month_over_Month[Yr_month]))

However, the reason I am using "MAX" is only because I have no idea which function to use to get a value in other column in the same table.

Since in this case there is only one "order product sales" in each month in each account, I can use "MAX" as a way out.

 

Wondering if there are more elegant solution for this kind of issue.

 

Thx

 

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @shihwenwu,

 

 

You can use SUM() function instead of MAX() function, which also works if you have more than one "order product sales" in each month for  each account.

 

pre_ops = CALCULATE(SUM(Month_over_Month[order_product_sales]),FILTER(Month_over_Month,Month_over_Month[account]=EARLIER(Month_over_Month[account])),PREVIOUSMONTH(Month_over_Month[Yr_month]))

 

For more details, please check the pbix as attached.

 

https://www.dropbox.com/s/nzaumqewiqvksl2/previous%20month%20and%20column%20filter.pbix?dl=0

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

1 REPLY 1
v-frfei-msft
Community Support
Community Support

Hi @shihwenwu,

 

 

You can use SUM() function instead of MAX() function, which also works if you have more than one "order product sales" in each month for  each account.

 

pre_ops = CALCULATE(SUM(Month_over_Month[order_product_sales]),FILTER(Month_over_Month,Month_over_Month[account]=EARLIER(Month_over_Month[account])),PREVIOUSMONTH(Month_over_Month[Yr_month]))

 

For more details, please check the pbix as attached.

 

https://www.dropbox.com/s/nzaumqewiqvksl2/previous%20month%20and%20column%20filter.pbix?dl=0

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

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!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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