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! Learn more

Reply
Scaart
Regular Visitor

Put max value from a filter on a measure

Hi,

 

I'm having trouble using measure to get max and min.

 

I only have one table with a column of id and a date (at the moment i have 300k id at the 1st august + the same 300k id at the 1st september).

The result I want is to show the count of id from M1 and M2, both month can be selected by the user.

 

First, i put a filter on the screen to allow the user to select months (I only showed month + year but it's a full date in the table)
The solution I imagined is to get the max month in a measure and the min month in another : 

Month_M1= month(CALCULATE(MAX(MYTABLE[DATE_CALCULATED]),ALLSELECTED(MYTABLE[DATE_CALCULATED].[Date])))
Month_M2= month(CALCULATE(MIN(MYTABLE[DATE_CALCULATED]),ALLSELECTED(MYTABLE[DATE_CALCULATED].[Date])))
 
Then use this two measure to create two others that will count the number of ID at each month :
Nb_ID_M1 = CALCULATE(COUNT(MYTABLE[ID]),filter(MYTABLE,month(MYTABLE[DATE_CALCULATED])=MYTABLE[Month_M1]))
Nb_ID_M2 = CALCULATE(COUNT(MYTABLE[ID]),filter(MYTABLE,month(MYTABLE[DATE_CALCULATED])=MYTABLE[Month_M2)))
 

Problem is that the first two measures Month_M1 and Month_M2 seems to get both month I select in the filter because when I put for example Month_M1 + DATE_CALCULATED on a table, that shows me 2 lines with 1st august and 1st september.

Do you have an idea how I can only get the max (and min) month selected ?
Thanks a lot !

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Scaart , Not very clear , one way is time intelligenec

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

 

 

another one is

 

Min month
new measure =
var _max = maxx(allselected(Date),Date[Date])
var _min = minx(allselected(Date),Date[Date])
return
calculate( sum(Table[Value]), filter('Date', eomonth('Date'[Date],0) >=eomonth(_min,0)  ))

 

 

Max month
new measure =
var _max = maxx(allselected(Date),Date[Date])
var _min = minx(allselected(Date),Date[Date])
return
calculate( sum(Table[Value]), filter('Date', eomonth('Date'[Date],0) >=eomonth(_max,0)  ))

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

1 REPLY 1
amitchandak
Super User
Super User

@Scaart , Not very clear , one way is time intelligenec

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))

 

 

another one is

 

Min month
new measure =
var _max = maxx(allselected(Date),Date[Date])
var _min = minx(allselected(Date),Date[Date])
return
calculate( sum(Table[Value]), filter('Date', eomonth('Date'[Date],0) >=eomonth(_min,0)  ))

 

 

Max month
new measure =
var _max = maxx(allselected(Date),Date[Date])
var _min = minx(allselected(Date),Date[Date])
return
calculate( sum(Table[Value]), filter('Date', eomonth('Date'[Date],0) >=eomonth(_max,0)  ))

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

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