I have created code to display the Top 10 N Manufacturers along with a grouped up “Other” Category using a Pseudo Table.
Everything was well with the world until I attempted to filter via another table that is in a one to many relationship (both way filtering).
I’ve tried so many variations, no colleague has been able to help either.
Here is the code that makes the Pseudo table: Pseudo Manufacturer Table = UNION(DISTINCT(All_Areas_Vehicles[Manufacturer]), DATATABLE("Manufacturer", STRING,{{"Others"}}))
And here is the original code I used to reflect the Top 10, Plus putting the rest into an “Other” Category:
Top N Manufacturer =
VAR TopManTable =
TOPN(
10,
ALLSELECTED('Pseudo Manufacturer Table'),
[Count_Manufacturer]
)
VAR TopManuCount =
CALCULATE(
[Count_Manufacturer],
KEEPFILTERS(TopManTable)
)
VAR OtherManu =
CALCULATE(
[Count_Manufacturer],
ALLSELECTED('Pseudo Manufacturer Table')
) -
CALCULATE(
[Count_Manufacturer],
TopManTable
)
VAR CurrentManu = SELECTEDVALUE('Pseudo Manufacturer Table'[Manufacturer])
RETURN
IF(
CurrentManu <> "Others",
TopManuCount,
OtherManu
)
Finally here is the latest code that I’ve created to try and make the filters from the other table not impact this:
Top N Manufacturer =
VAR TopNCount = 10
-- Calculate the top N manufacturers
VAR TopManTable =
TOPN(
TopNCount,
ALLSELECTED('Pseudo Manufacturer Table'[Manufacturer]),
[Count_Manufacturer]
)
-- Calculate the count for the top N manufacturers
VAR TopManuCount =
CALCULATE(
SUMX(
TopManTable,
[Count_Manufacturer]
)
)
-- Calculate the total count of manufacturers, considering all filters
VAR TotalManuCount =
CALCULATE(
[Count_Manufacturer],
REMOVEFILTERS('Pseudo Manufacturer Table'[Manufacturer])
)
-- Calculate the count for the "Others" category
VAR OtherManuCount =
TotalManuCount - TopManuCount
-- Get the currently selected manufacturer
VAR CurrentManu = SELECTEDVALUE('Pseudo Manufacturer Table'[Manufacturer])
RETURN
IF(
ISBLANK(CurrentManu),
BLANK(),
IF(
CurrentManu = "Others",
OtherManuCount,
IF(
CONTAINS(TopManTable, 'Pseudo Manufacturer Table'[Manufacturer], CurrentManu),
[Count_Manufacturer],
BLANK()
)
)
)
I just cannot workout why applying a filter from the other table is making the “Others” Category disappear, I’m getting desperate here as I’ve spend around 6 hours trying to make this work. Any help would be greatly appreciated!