Forum Discussion

worthywow1988's avatar
worthywow1988
Frequent Visitor
1 year ago
Solved

Lookup rank value?

Hi!

 

I have data where for a selected area I want to show the relative position compared to all the other areas. I've created a simple example:

 

AreaProductGroupSales
North1ABCA100
North2ABCA0
North3ABCA203
North4ABCA13
North5ABCA403
North6ABCA76
North7ABCA50
North8ABCA2
North1DEFA38
North2DEFA0
North3DEFA130
North4DEFA32
North5DEFA0
North6DEFA20
North7DEFA10
North8DEFA40
North1GHIB33
North2GHIB2
North3GHIB44
North4GHIB2
North5GHIB403
North6GHIB76
North7GHIB5
North8GHIB2
North1JKLB38
North2JKLB453
North3JKLB6
North4JKLB32
North5JKLB55
North6JKLB20
North7JKLB34
North8JKLB40

 

 

I've created a rank table

 

RANKING_TABLE = filter(SUMMARIZE (TABLE_DATA,[Area],[Product],"Sales Adjusted",[Sales Adjusted] ),TABLE_DATA[Sales Adjusted]>0)

 

In the TABLE_DATA_SUMMARY in this example I would like to show the quartile labels North1 for ABC and DEF as calculated in the RANKING_TABLE

 

I've just pulled "Upper Quartile" into the summary to show what I'm after - appreciate this wouldn't/doesn't work!

 

I've tried LOOKUPVALUE but didn't seem to work - should I be using this or another approach?

 

The pbix file is here Ranking Example.pbix 

 

Any advice really appreciated!

  • Hi Rohit - many thanks for your reply - much appreciated!

     

    In the end I got rid of the ranking tables since think was getting a bit messy. For neatness, simplicity and speed I just used min and max in the main table and then created a measure to see where the specific score sat in this range (lower, middle, top third). It's not actually ranking in the strict sense but is an ok measure in this situation since the scores are bounded and generally well distributed. Thanks again!

11 Replies

  • Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
    Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
    Please show the expected outcome based on the sample data you provided.

    Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • hi worthywow1988 ,

    Your goal is to display the Upper Quartile Label from the RANKING_TABLE in the TABLE_DATA_SUMMARY. Since LOOKUPVALUE is not working as expected, try using CALCULATE with FILTER instead.

    1. Create a Measure for Lookup:  Use CALCULATE to find the quartile label based on Area and Product:

    Upper_Quartile_Label_Summary =
    VAR SelectedArea = SELECTEDVALUE(TABLE_DATA[Area])
    VAR SelectedProduct = SELECTEDVALUE(TABLE_DATA[Product])
    
    RETURN
    CALCULATE(
        MAX(RANKING_TABLE[Upper Quartile Label]),
        RANKING_TABLE[Area] = SelectedArea,
        RANKING_TABLE[Product] = SelectedProduct
    )
    

    2. Add the Measure to TABLE_DATA_SUMMARY

    • Place Upper_Quartile_Label_Summary in your TABLE_DATA_SUMMARY table.
    • This will fetch the corresponding quartile label for the selected Area and Product.
     
     
    • worthywow1988's avatar
      worthywow1988
      Frequent Visitor

      Hi Rohit - many thanks for your reply - much appreciated!

       

      In the end I got rid of the ranking tables since think was getting a bit messy. For neatness, simplicity and speed I just used min and max in the main table and then created a measure to see where the specific score sat in this range (lower, middle, top third). It's not actually ranking in the strict sense but is an ok measure in this situation since the scores are bounded and generally well distributed. Thanks again!

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi,worthywow1988 . It's great to see that you solved your problem and that you shared the method to the forum,
        you can mark your option as a solution which will help other users in the forum.

        I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
        Best Regards,
        Carson Jian

         

  • You are creating a calculated table based on a measure. While technically possible, it does not make sense as there is no filter context.  Please explain the 1.2 factor.

    • worthywow1988's avatar
      worthywow1988
      Frequent Visitor

      Hi! This was just a quick simple example so will be slightly out of context. The 1.2 factor was just a dummy factor since wanted to show the summary ranking table contains measures not just values.

       

      To recap what I want to do is for a selected Area (e.g. North 1) and a selected Group (e.g. A) show where North 1 sits relative to the other areas. My actual dashboard is actually using third "quartiles" (tritiles?!). I've updated the example here Example v2 . So in the TABLE_DATA_SUMMARY I want the quartile to show as "HIGH" for ABC and "MID" for DEF from the ranking table

       

       

       

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi,lbendlin ,thanks for your concern about this issue.

    Your answer is excellent!
    I tried to open your pbix but it failed due to environmental reasons, would you be able to share your pbix test file again by way of github/OneDirve (please don't encrypt it)


    It looks like you tried to place the already created MEASURES into a calculation table that you created yourself and tried to filter them through the slicer.
    As lbendlin mentioned, your requirement is feasible from an implementation point of view.
    You could try using addcoulmns .

    ADDCOLUMNS function (DAX) - DAX | Microsoft Learn
     

    It is important to note:
    Measure requires a specific calculation context in DAX (Data Analysis Expressions) to be calculated correctly. If the necessary context is missing from the calculation table, the measure may not return the expected result.
    I recommend that you place the creation of the measure in the calculation table when you create it (as a variable spliced into this calculation table)

    but it is important to note that the calculation table is static, while the individual measure is dynamic (the calculation table is not affected by the slicer, while the individual measure is affected by the slicer)
    URL:

    Table Filter does not work based on slicer selecti... - Microsoft Fabric Community

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
    Best Regards,
    Carson Jian,
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • worthywow1988's avatar
      worthywow1988
      Frequent Visitor

      Hi Jian - thanks for your reply - much appreciated.

       

      I've been trying different approaches and combinations all day but not getting closer 😓

       

      I've created a new example and put it on OneDrive - hopefully you can download the pbix and source xls Example 2 

       

      What I'm trying to achieve is to get a lower third percentile and upper third percentile for the measure "Positive %" grouped by level and question. I then want to use this to check where the score in the little table on the left above sits ("Low" if below the lower percentile, "High" if above the upper percentile and "Middle" if in between. In excel I have checked/calculated the values I want (in green) but always seem to get the overall values in pink

       

       

      I have tried filtering, ALLEXCEPT etc. but nothing seems to work!

       

      Any help/advice welcome!

       

       

       

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        You still use measures to formulate your RANKING_TABLE.  What's the intent? Are these values impacted by user interaction ?

         

        Here's an alternative approach

        RANKING_TABLE = ADDCOLUMNS(filter(TABLE_DATA,[Sales]>0),"Sales Adjusted",[Sales]*1.2)
        
        Quartile Label = 
        var p = [Product]
        var LT= PERCENTILEX.INC(FILTER(RANKING_TABLE,[Product]=p),[Sales Adjusted], 0.33)
        var MT= PERCENTILEX.INC(FILTER(RANKING_TABLE,[Product]=p),[Sales Adjusted], 0.66)
        RETURN SWITCH(TRUE(),
        [Sales Adjusted]<LT,"LOW",
        [Sales Adjusted]<MT,"MED","HIGH")