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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
birudvora
Frequent Visitor

Unable to use Date Slicer in measure effectively.

Hi,

 

I am trying to use Date Slicer in the Measure but unable to do it successfully. I have explained my problem below. I appreciate if someone can look into this.

 

Table Columns: Date (Last date of the month), Portfolio Id, Manager, % Return

Slicer: I have Date Slicer in the report. I take Min Date and Max Date from that Date Slicer.  

Measure Average Return:  This measure calculates % Average Return for the date selected. 

 

Chart: Clustered Column Chart to show Measure AverageReturn by Manager.

Goal: I only want to include those portfolios for which data is available for all the months selected in the Date Slicer. For example if date slicer has selected entire 2017 & 2018. Then I want to include only those portfolios where we have data for all 24 months. 

 

Issue: The chart includes all the Portfolios even if data is not available for all the months.

 

Measures I have created to achieve this: 

maxdate = calculate(MAX(Data[Date]),ALLSELECTED())
mindate = calculate(min(Data[Date]),ALLSELECTED())
 

nMonths = CountRows('Data') This correctly calculates number months for which data is available

FilteredNMonths =

(Year([maxdate]) - Year([mindate]))*12 + MONTH([maxdate]) - Month([mindate])+1

This correctly calculates number of months Date Filter has selected.

 

Return = PRODUCT(Data[% Return])

AverageReturn = 

averagex(filter(SUMMARIZE(Data, Data[PorfolioId], "toAverage", [Return]),[nMonths]=[FilteredNMonths]),[Return])
 
Many Thanks for looking into this.
 
-
Birud
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Have a month year column in your table too. Take a count distinct of that. Count distinct of that should be equal to date diff on min and max dates . Even Month-year of date table should work

AverageReturn = 
var _maxdate = calculate(MAX(Data[Date]),ALLSELECTED())
var _mindate = calculate(min(Data[Date]),ALLSELECTED())
var _diff = datediff(mindate,maxdate,month)
return
averagex(filter(SUMMARIZE(Data, Data[PorfolioId], "toAverage", [Return],"_dist" ,distinctcount(data[Month-year])),[_dist]=_diff),[Return])
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

Have a month year column in your table too. Take a count distinct of that. Count distinct of that should be equal to date diff on min and max dates . Even Month-year of date table should work

AverageReturn = 
var _maxdate = calculate(MAX(Data[Date]),ALLSELECTED())
var _mindate = calculate(min(Data[Date]),ALLSELECTED())
var _diff = datediff(mindate,maxdate,month)
return
averagex(filter(SUMMARIZE(Data, Data[PorfolioId], "toAverage", [Return],"_dist" ,distinctcount(data[Month-year])),[_dist]=_diff),[Return])
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


@amitchandak wrote:

Have a month year column in your table too. Take a count distinct of that. Count distinct of that should be equal to date diff on min and max dates . Even Month-year of date table should work

 

AverageReturn = 
var _maxdate = calculate(MAX(Data[Date]),ALLSELECTED())
var _mindate = calculate(min(Data[Date]),ALLSELECTED())
var _diff = datediff(mindate,maxdate,month)
return
averagex(filter(SUMMARIZE(Data, Data[PorfolioId], "toAverage", [Return],"_dist" ,distinctcount(data[Month-year])),[_dist]=_diff),[Return])

 


Hi Amit,

 

Thank you for the solution. This worked perfectly for us.

 

Regards

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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