Forum Discussion

derekli1700's avatar
derekli1700
Icon for Helper III rankHelper III
1 year ago
Solved

Matrix Table Shows More Than Top 5 Customers per Store When Adding Year/Month – How to Fix

Hi - Currently my table (named Overview) is displaying Sites (via distinct site table) and Customers (via distinct customer table) as the Matrix Table's rows and the overall store sales + top 5 customer sales (depending on the time period picked).

Data sheet hyperlink

PBIX file hyperlink

 

I'm experiencing a problem where:

1. I can't seem to make a Top/Bottom 20 stores slicer (based off sales)

2. Adding Date columns to my Matrix Table rows removes my top 5 Customers row condition and instead shows 6 or more customer rows/exceeds query resources

 

 

To illustrate what i'm doing currently - I made the table's sales value by these measures:

Total Sales = SUM( Overview[Sales])

Then i used this measure as the Matrix Table value:

MEASURE-SALES = IF( ISINSCOPE( 'Unique Customers'[Customer] ), [Total Sales], CALCULATE( [Total Sales], REMOVEFILTERS( 'Unique Customers'[Customer] ) ) )

As mentioned before - i also made the table show each store's top 5 customers via this rank:

Customer Rank = VAR BaseTable = ADDCOLUMNS(
    CALCULATETABLE(
        SUMMARIZE(
            Overview, 
            'Unique Customers'[Customer],
            'Unique Stores'[Store]
        ),
        REMOVEFILTERS( 'Unique Customers' )
    ),
    "@val", [Total Sales]
)
VAR Result = RANK(
    SKIP,
    BaseTable,
    ORDERBY( [@val], DESC ),
    PARTITIONBY( 'Unique Stores'[Store] )
)
RETURN Result

then i set this measure as = 1 in the table's filter

Customer is visible = VAR CustomerRank = [Customer Rank]
VAR Result = IF( ( CustomerRank <= 5 && NOT ISBLANK( CustomerRank ) )
    || NOT ISINSCOPE( 'Unique Customers'[Customer] ), 1 )
RETURN Result

 

My date table is below for reference (capped at current month for YOY measure purposes not mentioned above):

Date = 
ADDCOLUMNS (
    CALENDAR (
        DATE (2023, 1, 1),
        DATE (2025, 4, 30)
    ),
    "Year", YEAR([Date]),
    "Year-Month", FORMAT([Date], "yyyy-MM"),
    "Year-Month sort", EOMONTH([Date], 0)
)

 Would like some guidance- thanks

  • Anonymous's avatar
    Anonymous
    1 year ago
    Hi derekli1700 ,
    Replace it with following DAX :

    Customer Is Visible =
    VAR RankValue = [Customer Rank]
    RETURN
    IF(RankValue <= 5 && NOT ISBLANK(RankValue), 1, 0)

    If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so other members can easily find it.

    Best Regards,
    Sreeteja.
    Community Support Team 

     

4 Replies

  • Hi derekli1700 ,


    Thanks for the detailed breakdown, that helps a lot.

    From what I see, the issue is happening because when you add a Date column to the Matrix rows, it changes the evaluation context of your [Customer Rank] measure. That causes the ranking logic to break and show more than 5 customers per store.

    Here’s what you can try:

    1. Use RANKX instead of SUMX in your [Customer Rank] measure. Right now, you're summing ranks, which doesn’t actually rank the customers. Try something like:
    Customer Rank =
    RANKX(
        FILTER(
            ALLSELECTED('Unique Customers'[Customer]),
            NOT ISBLANK([Total Sales])
        ),
        [Total Sales],
        ,
        DESC
    )
    1. Then update your visibility measure like this:
    Customer is visible =
    VAR Rank = [Customer Rank]
    RETURN
    IF(
        Rank <= 5 && NOT ISBLANK(Rank),
        1
    )
    1. Apply this measure as a visual-level filter on your Matrix: Customer is visible = 1

    Also, make sure your Matrix rows are structured like:

    • Store
    • Customer
    • (Optional) Date hierarchy, but be careful with granularity — too much detail can break the ranking logic due to context shifts.

    Let me know if you want help adapting this to work with Top 20 Stores as well.

    If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
    translation and formatting supported by AI

    • derekli1700's avatar
      derekli1700
      Icon for Helper III rankHelper III

      Hi, thanks - regarding the customer is visible measure, it says "The syntax for 'Rank' is incorrect. (DAX(VAR Rank = [Customer Rank]RETURNIF( Rank <= 5 && NOT ISBLANK(Rank), 1))).", is there a way to fix this? thanks!

      • Anonymous's avatar
        Anonymous
        Not applicable
        Hi derekli1700 ,
        Replace it with following DAX :

        Customer Is Visible =
        VAR RankValue = [Customer Rank]
        RETURN
        IF(RankValue <= 5 && NOT ISBLANK(RankValue), 1, 0)

        If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so other members can easily find it.

        Best Regards,
        Sreeteja.
        Community Support Team