Forum Discussion

harmon-tuazon's avatar
harmon-tuazon
New Member
2 years ago
Solved

TOPN Functions returns the same value as my COUNT aggregate function

Hey everyone. Sorry super new to posting. I have a measure that supposed to return the top 10 values of a table I'm working with (using Calculate and TopN). I have another measure that just aggregates values (using Count). However, as seen on the matrix table screenshot I attached here, the TOPN measure returns the same values as my other measure. Any idea why the TOPN isn't filtering the calculation? TIA

  • Hi,

    I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

    Please check the below picture and the attached pbix file whether it suits your requirement.

     

     

    Sales: = 
    SUM(data[sales])

     

    % top 3 sales: =
    VAR _allsales =
        CALCULATE ( [Sales:], ALL ( data[category] ) )
    VAR _topsales =
        CALCULATE ( [Sales:], TOPN ( 3, ALL ( data[category] ), [Sales:], DESC ) )
    RETURN
        DIVIDE ( _topsales, _allsales )
    

     

2 Replies

  • Hi,

    I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

    Please check the below picture and the attached pbix file whether it suits your requirement.

     

     

    Sales: = 
    SUM(data[sales])

     

    % top 3 sales: =
    VAR _allsales =
        CALCULATE ( [Sales:], ALL ( data[category] ) )
    VAR _topsales =
        CALCULATE ( [Sales:], TOPN ( 3, ALL ( data[category] ), [Sales:], DESC ) )
    RETURN
        DIVIDE ( _topsales, _allsales )
    

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks for the reply from Jihwan_Kim.

     

    Hi harmon-tuazon ,

     

    Here I have another idea in mind, and I would like to share it for reference.Sample data is as follows:

     

    1.Create two measure:

     

    #Meal Kits = COUNT(financials[Index])
    
    
    #Top 10 Meal Kits Ordered =
    VAR _p =
        SELECTEDVALUE ( financials[Product] )
    RETURN
        MAXX (
            FILTER (
                TOPN (
                    3,
                    SUMMARIZE (
                        ALLSELECTED ( financials ),
                        'financials'[Product],
                        "Top",
                            CALCULATE (
                                COUNT ( 'financials'[Index] ),
                                ALLEXCEPT ( financials, financials[Product] )
                            )
                    ),
                    [Top], DESC
                ),
                'financials'[Product] = _p
            ),
            [Top]
        )
    

     

     

    2.The top three product totals were successfully obtained using the measure just created.

     

     

    Best Regards,
    Zhu
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!