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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
u92690
Frequent Visitor

Complex filter context

Hi all,

 

Following  this video of Alberto Ferrari i managed to write the code for a dynamic "others". So far, so good. The problem comes when I want to calculate differences vs the last year, as I need to recalculate for the last year the sum of the elements that are part of the rest in the current year. I wrote this, but the "others" row is not showing the right value. Any ideas?

 

Sales LY =
var TotalSales=
CALCULATE([Sales],REMOVEFILTERS('Countrytable'[Country]),SAMEPERIODLASTYEAR(Caleandar[Date]))
RETURN
IF(ISINSCOPE('Countrytable'[Country]),
var countryrank= 'TopN'[Valor TopN]
var SelectedOthers = SELECTEDVALUE('Countrytable'[Country]) = "Others"
var Tablecountries=ADDCOLUMNS(ALLSELECTED('Countrytable'[Country]),"@sales",CALCULATE([Sales],SAMEPERIODLASTYEAR(Caleandar[Date])))
var Topcountries = TOPN(countryrank,Tablecountries,[@sales],DESC)
var CountryTop = Sumx(countryrank,[@sales])
var Result = if(SelectedOthers,TotalSales-CountryTop ,CALCULATE([[Sales]l],SAMEPERIODLASTYEAR(Caleandar[Date])))
RETURN Result,TotalSales)
 
All values that are inscope are correctly calcualted, but not the "others". When doing (TotalSales-CountryTop), the script is only able to compute the ContryTop value. Instead, the total sales appear 0. The total (out of scope) works fine, so i guess it's regarding the filter context withing the ISINSCOPE function. Help!
 
@amitchandak @Ibendlin @parryk2 @AlexisOlson
1 REPLY 1
Anonymous
Not applicable

Hi @u92690 

Can you provide the data of the table related to your formula ? if possible, please provide your pbix file(remove sensitive info), which will help us to better judge the problem.

 

Best Regard

Community Support Team _ Ailsa Tao

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.