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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-yetao1-msft
Community Support
Community Support

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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