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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

TopN + Others - Circular reference

Hi all,

I've been struggling with a formula for a few days now so I'm reaching out for help.  I have read multiple articles and posts but still can't figure out what's causing the circular reference error in this statement.  I'm following an example I found online for creating Top N and "other" for customer tickets.  Below is my statement -

CSTs TopN+Others =
VAR RankCSTVolume = RANKX(ALL('CSTs from 2018 to current'),[Service Tickets Total],,DESC)
return
if (RankCSTVolume<=10, 'CSTs from 2018 to current'[Cat2andCat3], "Others")
 
The only calculated field is 'Service Tickets Total' -
Service Tickets Total =
CALCULATE(
    SUM('CSTs from 2018 to current'[Service Tickets]),
    ALLSELECTED('CSTs from 2018 to current'[Service Tickets])
)
Any ideas appreciated!  Thanks!
10 REPLIES 10
Anonymous
Not applicable

Hi @Anonymous ,

 

If the last post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

Try like

CSTs TopN+Others =
VAR RankCSTVolume = RANKX(ALLselected('CSTs from 2018 to current'),CALCULATE(
    SUM('CSTs from 2018 to current'[Service Tickets])
),,DESC)
return
if (RankCSTVolume<=10, 'CSTs from 2018 to current'[Cat2andCat3], "Others")
 
 

CSTs TopN+Others =
VAR RankCSTVolume = RANKX(ALL('CSTs from 2018 to current'),CALCULATE(
    SUM('CSTs from 2018 to current'[Service Tickets])
),,DESC)
return
if (RankCSTVolume<=10, 'CSTs from 2018 to current'[Cat2andCat3], "Others")
Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks @amitchandak ... I think it's close.  I'm still getting an error on the last statement -

if (RankCSTVolume<=10, 'CSTs from 2018 to current'[Cat2andCat3], "Others")

The error is - Cannot find name '[Cat2andCat3]'

Seems like a syntax error but I don't see why.  It seems to only accept a caclulated field.

Try like.

if (RankCSTVolume<=10, firstnonblank('CSTs from 2018 to current'[Cat2andCat3],blank()), "Others")

 

But row context is very important

Check how I have taken care of that in date diff :https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak thanks for your help.  Unfortunately when I replaced the 'if' statement I recieved a circular reference error.  I tried to create a sample file to share with you so that you could see the data and error, but apparently this board restricts attachments.  I also tried to break up the statements into two statements thinking that might address the circular reference but no luck.  Open to any other ideas.  Below is the last statement I used.

 

CSTs TopN+Others = 
VAR RankCSTVolume = RANKX(ALLselected('CSTs from 2018 to current'),CALCULATE(
    SUM('CSTs from 2018 to current'[Service Tickets])
),,DESC)
return
if (RankCSTVolume<=10, firstnonblank('CSTs from 2018 to current'[Cat2andCat3],blank()), "Others")

 

See if you can replicate your issue on this file

https://www.dropbox.com/s/drp7gscx3w1liyc/sales_analytics_cumm.pbix?dl=0

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak   the statements works perfectly on your data!  This tells me the error has somthing to do with my data.  I'll keep digging to try and find out why. 

 

Items TopN+Others = 
VAR RankItemSales = RANKX(ALLSELECTED('Item'),CALCULATE(SUM('Sales'[Net Sales])),,DESC)
return
if (RankItemSales<=10,('Item'[Brand]),"Others")

 

You are creating a column in your data and I think we were trying for the measure. I created as measure and it worked

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Create a measure or In case you want a column. Create two. Also, in case of column rank will not take the Aggregated column. Also no need of first non blank

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak  thanks will do.  When I used your link I was able to create a drop box account!  I'm a newbie so this is all somewhat new to me.  Anyhow.. I now have a link that I can share with you too.   I tried to insert the link directly into the reply but that didn't work for some reason.  Hopefully you can access this.  In the meantime, I will try to recreate the issue on your file.

 

https://www.dropbox.com/s/gd1pgjx82ib98ij/RankTopNandOthers.pbix?dl=0

  

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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