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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

SelectedValue in a filter

This maybe a little complicated to understand.

 

  1. I want to filter my results by period. (To figure out my performance index)

 

  1. My performance index is base on the last 3 periods.

 

  1. To do that I need to do the SUM(*******) of my product, and then FILTER(My period = SELECTEDVALUE - 1 then repeat with -2 then repeat with -3) to finally do an average of all three of my periods. (The average work's fine)

 

The result alway's comes out blank, but If I put my filter like this (Let's say we are currently period 10) FILTER(My period= 10-1 or 2 or 3) it work's. 

 

The SELECTEDVALUE would of course be the slicer of my selected period, so in this example, 10. 

 

Thanks

2 REPLIES 2
Anonymous
Not applicable

// Assumptions:
// 1. There is a DIMENSION, Period, that stores periods.
// Each period has a unique PeriodId and those
// are increasing by 1.
// 2. All dimensions are connected to your fact table
// via 1:* and filtering is one-way only and slicing
// is only done via dimensions (all data columns in
// the fact table are hidden).
//
// Since I don't have any more information, this is
// the best I can do. I think you have a Calendar
// in our model, so if you do, then you should state
// how you want our measure to work with granularities
// higher/lower than your periods. You have not stated it
// here.

[Measure] =
var __onePeriodSelected = HASONEVALUE( Period[PeriodId] )
var __selectedPeriod = SELECTEDVALUE( Period[PeriodId] )
var __sumForLast3Periods =
	CALCULATE(
		SUM( FactTable[Amount] ),
		Periods[PeriodId] < __selectedPeriod,
		Periods[PeriodId] >= __selectedPeriod - 3,
		ALL( Periods )
	)
var __avg =	__sumForLast3Periods / 3
var __thereAreEnoughPeriods =
	CALCULATE(
		min( Period[PeriodId] ),
		all( Period )
	) <= __selectedPeriod - 3
var __shouldCalculate =
	__onePeriodSelected && __thereAreEnoughPeriods
return
	if( __shouldCalculate, __avg )

 

Best

D

Greg_Deckler
Community Champion
Community Champion

Could be made easier to understand. Sample data. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.