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
H3nning
Resolver I
Resolver I

Top 3 of a category by Measure and other category

Hi,

maybe someone can halp me with a ranking function please.

Im trying to build a ranking based on a fact table:

AgentSupplierSuccess
AXTRUE
AXFALSE
AYFALSE
AYFALSE
BXTRUE
BXFALSE
BYTRUE
BYTRUE
BYFALSE

 

I built a measure [RateOfSuccess] for the percentage of success. For example Agent A hat a success rate of 50% with supplier X and 0% with Y and 25% overall. Please use that measure in a possible solution, because it stands for a much more complex measure in reality.

 

Now I want to give a Top N List auf Suppliers for every Agent. The result for my little example would be:

Agent AAgent B
XY
YX

 

Or if I only want Top 1:

Agent AAgent B
XY

 

Suggestions how to accomplish?

 

Thanks so much in advance 🙂

1 ACCEPTED SOLUTION

Hi @H3nning,

You can try modify the collection part to add a filter and invoke the 'success' expression results as condition:

formula =
VAR currAgent =
    SELECTEDVALUE ( 'Table'[Agent] )
VAR summary =
    SUMMARIZE (
        ALLSELECTED ( 'Table' ),
        [Agent],
        [Supplier],
        "c_Supplier",
            CALCULATE (
                COUNT ( 'Table'[Supplier] ),
                FILTER ( 'Table', [Success] = "True" )
            )
    )
RETURN
    CONCATENATEX (
        TOPN ( 1, FILTER ( summary, [Agent] = currAgent ), [c_Supplier] ),
        [Supplier],
        ","
    )

 

If the above formula also not help, can you please share a pbix file or some dummy data that keep the raw data structure, Dax formulas to upload and paste the share link here? It should help us clarify your scenario and test to coding formula. (notice: please not attach any sensitive data in it)

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

 

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

HI @H3nning,

You can try to use the following measure formula to get the top supplier based on current agent group:

formula = 
VAR currAgent =
    SELECTEDVALUE ( 'Table'[Agent] )
VAR summary =
    SUMMARIZE (
        ALLSELECTED ( 'Table' ),
        [Agent],
        [Supplier],
        "c_Supplier", CALCULATE ( COUNT ( 'Table'[Supplier] ), 'Table'[Success] = TRUE () )
    )
RETURN
    CONCATENATEX (
        TOPN ( 1, FILTER ( summary, [Agent] = currAgent ), [c_Supplier] ),
        [Supplier],
        ","
    )

Screenshot 2023-05-30 151602.pngNotice: the sample table success field stored the bool type values, if your table are used text type, please change the TRUE function in expression to text value to get correct results.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi, thank you for your reply. Can you provide the code with using a measure instead of building the measure in the code? In my example the rate of success stands for a much more complicated measure. Lats call it [RateOFSuccess] and it is already rthere and is to be used. How can i use that measure in your formula?

Hi @H3nning,

You can try modify the collection part to add a filter and invoke the 'success' expression results as condition:

formula =
VAR currAgent =
    SELECTEDVALUE ( 'Table'[Agent] )
VAR summary =
    SUMMARIZE (
        ALLSELECTED ( 'Table' ),
        [Agent],
        [Supplier],
        "c_Supplier",
            CALCULATE (
                COUNT ( 'Table'[Supplier] ),
                FILTER ( 'Table', [Success] = "True" )
            )
    )
RETURN
    CONCATENATEX (
        TOPN ( 1, FILTER ( summary, [Agent] = currAgent ), [c_Supplier] ),
        [Supplier],
        ","
    )

 

If the above formula also not help, can you please share a pbix file or some dummy data that keep the raw data structure, Dax formulas to upload and paste the share link here? It should help us clarify your scenario and test to coding formula. (notice: please not attach any sensitive data in it)

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

 

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.