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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Max of table and not of record in table

Hi,

 

I am trying to create a measure that returns the volume of the current month. The current month in this example is (2021/05/01) - which corresponds to the max date of the table. See Table 1 below.
The following is the measure:

 

Current Month = 
VAR MaxYear = YEAR(MAX('Table1'[Date]))
VAR MaxMonth = MONTH(MAX('Table1'[Date]))

RETURN
CALCULATE(SUM('Table1'[Volume]),'Table1'[Year]=MaxYear,'Table1'[Month]=MaxMonth)

 

 

However, when I add the measure to the table (See Table 2), it returns the volume for the current month that corresponds to the max date for that customer and not the max date for the table - which can be seen by "Company 3" in Table 2, the date corresponds to (2020/01/01) as opposed ti (2021/05/01). I do not want to hard code the date and year as that would mean I need to update the measure every month. How can I fix the value such that it returns the max date of the table column and does not change the context based on the record its applied to?

 

Table1

CustomerDateYearMonthVolume
Company 12019/05/012019522
Company 12020/05/01202053
Company 12021/05/01202154
Company 22020/01/012020119
Company 22021/05/012021526
Company 32020/01/01202017

 

Table2

CustomerCurrent Month
Company 14
Company 226
Company 37

 

Thank you

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , If you want customer wise max, Try like

 

Current Month =
VAR MaxYear = YEAR(MAX('Table1'[Date]))
VAR MaxMonth = MONTH(MAX('Table1'[Date]))

RETURN
CALCULATE(SUMX(values('Table'[Customer]),calculate(sum('Table1'[Volume]))),filter('Table','Table1'[Year]=MaxYear && 'Table1'[Month]=MaxMonth))

 

Max based on table

 

Current Month =
VAR MaxYear = YEAR(MAXX(allselected('Table1'), 'Table'[Date]))
VAR MaxMonth = MONTH(MAXX(allselected('Table1'), 'Table'[Date]))

RETURN
CALCULATE(SUM('Table1'[Volume]),,filter('Table','Table1'[Year]=MaxYear && 'Table1'[Month]=MaxMonth))

 

 

Today ----
Current Month =
VAR MaxYear = YEAR(today())
VAR MaxMonth = MONTH(today())

RETURN
CALCULATE(SUM('Table1'[Volume]),'Table1'[Year]=MaxYear,'Table1'[Month]=MaxMonth)

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

@Anonymous , If you want customer wise max, Try like

 

Current Month =
VAR MaxYear = YEAR(MAX('Table1'[Date]))
VAR MaxMonth = MONTH(MAX('Table1'[Date]))

RETURN
CALCULATE(SUMX(values('Table'[Customer]),calculate(sum('Table1'[Volume]))),filter('Table','Table1'[Year]=MaxYear && 'Table1'[Month]=MaxMonth))

 

Max based on table

 

Current Month =
VAR MaxYear = YEAR(MAXX(allselected('Table1'), 'Table'[Date]))
VAR MaxMonth = MONTH(MAXX(allselected('Table1'), 'Table'[Date]))

RETURN
CALCULATE(SUM('Table1'[Volume]),,filter('Table','Table1'[Year]=MaxYear && 'Table1'[Month]=MaxMonth))

 

 

Today ----
Current Month =
VAR MaxYear = YEAR(today())
VAR MaxMonth = MONTH(today())

RETURN
CALCULATE(SUM('Table1'[Volume]),'Table1'[Year]=MaxYear,'Table1'[Month]=MaxMonth)

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
Anonymous
Not applicable

Thank! I used max based on table.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors