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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
av9
Helper III
Helper III

Calculate date value for date before MAX date

Hi, In my model I have sales data that is populated for each country at different times of the month. Therefore I can have data for Country 'Belgium' as at '31 Oct' but Norway will be '30 Sep'.

 

So I use the last sales date to calculate total sales for each country; 

Country Refresh Date = CALCULATE(MAX(Sales[Date]), REMOVEFILTERS(Customer[Customer]))
 
Sum Sales Amount =
CALCULATE
( SUMX(VALUES(Country[Country]),SUM(Sales[Amount])),FILTER(Sales, (MAX(Sales[Date])=[Country Refresh Date])))
 

If I want to see the previous months sales data, how do I calculate the prev month based on the date of the last Country Refresh Date per country?

 

Attached is the PBIX I am using.

https://drive.google.com/file/d/1OvSLP05PXI7ZGEkwYC5KQFJ_9qhbQMaq/view?usp=sharing

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@av9 , Try measures like


Sum Sales Amount =
CALCULATE
( SUMX(VALUES(Country[Country]),SUM(Sales[Amount])),FILTER(Sales,Sales[Date]=CALCULATE(max(Sales[Date]),ALLEXCEPT(Country,Country[Country]))))

Last month Sales Amount =
CALCULATE
( SUMX(VALUES(Country[Country]),SUM(Sales[Amount])),FILTER(Sales,Sales[Date]=eomonth(CALCULATE(max(Sales[Date]),ALLEXCEPT(Country,Country[Country])),-1)))

 

////or

Sum Sales Amount =
CALCULATE
( SUMX(VALUES(Country[Country]),SUM(Sales[Amount])),FILTER(Sales,eomonth(Sales[Date],0)=CALCULATE(max(Sales[Date]),ALLEXCEPT(Country,Country[Country]))))

Last month Sales Amount =
CALCULATE
( SUMX(VALUES(Country[Country]),SUM(Sales[Amount])),FILTER(Sales,eomonth(Sales[Date],0)=eomonth(CALCULATE(max(Sales[Date]),ALLEXCEPT(Country,Country[Country])),-1)))

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

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@av9 , Try measures like


Sum Sales Amount =
CALCULATE
( SUMX(VALUES(Country[Country]),SUM(Sales[Amount])),FILTER(Sales,Sales[Date]=CALCULATE(max(Sales[Date]),ALLEXCEPT(Country,Country[Country]))))

Last month Sales Amount =
CALCULATE
( SUMX(VALUES(Country[Country]),SUM(Sales[Amount])),FILTER(Sales,Sales[Date]=eomonth(CALCULATE(max(Sales[Date]),ALLEXCEPT(Country,Country[Country])),-1)))

 

////or

Sum Sales Amount =
CALCULATE
( SUMX(VALUES(Country[Country]),SUM(Sales[Amount])),FILTER(Sales,eomonth(Sales[Date],0)=CALCULATE(max(Sales[Date]),ALLEXCEPT(Country,Country[Country]))))

Last month Sales Amount =
CALCULATE
( SUMX(VALUES(Country[Country]),SUM(Sales[Amount])),FILTER(Sales,eomonth(Sales[Date],0)=eomonth(CALCULATE(max(Sales[Date]),ALLEXCEPT(Country,Country[Country])),-1)))

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

The measures didn't quite work as expected, but it did give the idea to use Eomnth to calculate the previous month from max date.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.