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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is 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
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 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.

Top Solution Authors