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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors