Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Filter Top N% Column Values by Other Column Values

I am migrating one report from Excel to Power BI. So, in Power BI I need to implement the same Excel Filter shown in attached screenshot. Basically the logic needs to be like, the Values in Column C are to be summarized by Values in Column A and then the Values in Column B need to be filtered(Only Top 60% Values) by summarized Values of Column C.

NOTE: Column B has multiple Sub-Values for Each Value in Column A as you can see a (+) sign before each value in Column A 

 

Can someone help with the DAX Logic that need to be followed in order to achieve this functionality.

18 Replies

  • Anonymous file attached for your reference, enjoy!!

     

    ✨ Follow us on LinkedIn

     

    Learn about conditional formatting at Microsoft Reactor

    My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ā¤ Kudos if my solution helped. šŸ‘‰ If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    ⚔ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚔

    • smpa01's avatar
      smpa01
      Icon for Community Champion rankCommunity Champion

      Thanks parry2k AlexisOlson  for the quick response. parry2k  will study it and might get back to you with any follow uo question I might have.

       

      Anonymous  guess you are sorted now.

    • Anonymous's avatar
      Anonymous
      Not applicable

      parry2k Thanks a lot, I'll apply the same dax logic and will let you know about the results that I will get with the actual data.

    • Anonymous's avatar
      Anonymous
      Not applicable

      parry2k I think we are close to achieving the required functionality. Thanks Again.

       

      Is it also possible to have a measure column in the same matrix visual which can show the Sum of Number of Corresponding Filtered Suppliers (Using Number Supplier Orders column from Table). Please refer attached screenshot.

  • Anonymous attached

     

    ✨ Follow us on LinkedIn

     

    Learn about conditional formatting at Microsoft Reactor

    My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ā¤ Kudos if my solution helped. šŸ‘‰ If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    ⚔ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚔

    • Anonymous's avatar
      Anonymous
      Not applicable

      Many Thanks parry2k for the solution. I'll try this now with the large dataset.

  • Anonymous I think this will do it, I guess this is what you are looking for:

     

  • smpa01's avatar
    smpa01
    Icon for Community Champion rankCommunity Champion

    Anonymous  sure no problem. Can you please provide some data and desired output please.

    • Anonymous's avatar
      Anonymous
      Not applicable
      Local Product Group UnitSupplierOrder Value USD BRNumber Suppliers Order
      PRAPTP20485,2501
      PRAPTP204985,0001
      PRAPTP205020,7461
      PRAPTP2051661
      PRAPTP205210,0001
      PRAPTP205366,0001
      PRAPTP20549,9951
      PRAPTP205550,0001
      PRAPTP20568991
      PRAPTP205724,0201
      PRADTP20588,9631
      PRADTP20598,012,0001
      PRADTP20601,3791
      PRADTP20611,2001
      PRADTP2062697,2161
      PRADTP20633,075,7661
      PRADTP20641,4801
      PRADTP206543,8201
      PRADTP206645,0001
      PRADTP206710,5001
      PRADTP20681,453,0001
      PRADTP206928,7371
      PRADTP20707,0001
      PRADTP207182,3121
      PCDVTP20725,0701
      PCDVTP207320,0001
      PCDVTP2074840,0001
      PCDVTP2075133,9801
      PCDVTP2076205,2281
      PCDVTP20771,043,6371
      PCDVTP2078554,8001
      PCDVTP2079134,3531
      PCDVTP2080173,0581
      PCDVTP20812,3001
      PCDVTP208286,8371
      PCDVTP20833,1661
      PCDVTP20841,608,5801
      PCDVTP2085396,8981
      PCDVTP20862221
      PCDVTP20871,317,1361
      PCDVTP208820,0001
      PCDVTP2089220,0001
      PCDVTP2090120,0001
      PRACTP2091172,5001
      PRACTP20926,4801
      PRACTP209338,4001
      PRACTP209415,4601
      PRACTP2095145,3601
      PRACTP209610,0001
      PRACTP209732,0001
      PRACTP20982,5001
      PRACTP2099105,6421
      PRACTP210031,7301
      PRACTP2101188,8501
      PRACTP21027,0001
      PRACTP21034,8001
      PRACTP210494,8751
      PRACTP21053,329,7461
      PRACTP2106250,3751
      PRACTP210732,1831
      PRACTP21082,4741
      PRACTP21095891
      PRGPTP21103,0711
      PRGPTP21113,7901
      PRGPTP2112223,8971
      PRGPTP21135,9301
      PRGPTP21143261
      PRGPTP21155,7251
      PRGPTP2116176,3911
      PRGPTP211712,2701
      PRGPTP211824,9381
      PRGPTP21194921
      PRGPTP21206,4471
      PRGPTP212169,6451
      PRGPTP212216,8861
      PRGPTP2123255,3361
      PRGPTP21241,0421
      PRGPTP21258,3161
      PRGPTP212639,1121
      PRGPTP21272,4381
      PRGPTP21281,3651
      PRGPTP2129603,0081
      PRGPTP2130184,7421
      PRGPTP213130,2991
      PRGPTP2132185,7941

       

      You can use the above table as sample data, for convenience I have kept the column header of this table same as those shown in the attached screenshot(in above post). 

      Regarding Desired Output, I need the data representation to be same as that shown in the attached screenshot(in above post).

      • smpa01's avatar
        smpa01
        Icon for Community Champion rankCommunity Champion

        Anonymous 

        Basically the logic needs to be like, the Values in Column C are to be summarized by Values in Column A and then the Values in Column B need to be filtered(Only Top 60% Values) by summarized Values of Column C

        Just so I understand,  Order Value USD BR needs to be summarized by Local Product Group Unit 

        which is the following

         

        and then the Values in Column B need to be filtered(Only Top 60% Values) by summarized Values of Column C - so does it mean that DAX needs to return the top 60% (Order Value USD BR/sum of Order Value USD BR by Local Product Group Unit)

         

        If I follow the above, for the given dataset, DAX only needs to return this row only as everything else is <=60%

         

         

        Please confirm

         

         

  • smpa01's avatar
    smpa01
    Icon for Community Champion rankCommunity Champion

    Anonymous  

     

    I don't think PBI has anything which utilizes % as TOPN

     

    What you want can be returned through a DAX table function but can this be done with a measure. looping AlexisOlson  and parry2k  attached a pbix for your refrerence

     

    DAX Table function that returns the derived table, but offcourse that is not desired. The foloowing DAX query returns if a the same PIVOT table was filtered in excel

     

     

     

    Measure =
    VAR _1 =
        ADDCOLUMNS ( 'Table 1', "_pct", [pct] )
    VAR _2 =
        ADDCOLUMNS (
            _1,
            "rank",
                RANKX (
                    FILTER (
                        _1,
                        'Table 1'[Local Product Group Unit]
                            = EARLIER ( 'Table 1'[Local Product Group Unit] )
                    ),
                    [_pct],
                    ,
                    DESC
                )
        )
    VAR _3 =
        ADDCOLUMNS (
            _2,
            "runningPct",
                SUMX (
                    FILTER (
                        _2,
                        'Table 1'[Local Product Group Unit]
                            = EARLIER ( 'Table 1'[Local Product Group Unit] )
                            && [rank] <= EARLIER ( [rank] )
                    ),
                    [_pct]
                )
        )
    VAR _4 =
        ADDCOLUMNS (
            ADDCOLUMNS ( _3, "is60", IF ( [runningPct] >= 0.6, 0, [runningPct] ) ),
            "is60_2", IF ( [runningPct] >= 0.6, [runningPct], 0 )
        )
    VAR _5 =
        ADDCOLUMNS (
            _4,
            "rank2",
                IF (
                    [is60] = 0,
                    RANKX (
                        FILTER (
                            _4,
                            'Table 1'[Local Product Group Unit]
                                = EARLIER ( 'Table 1'[Local Product Group Unit] )
                        ),
                        [is60_2],
                        ,
                        asc,
                        DENSE
                    )
                )
        )
    VAR _6 =
        FILTER ( _5, [is60] <> 0 )
    VAR _7 =
        FILTER ( _5, [rank2] = 2 )
    VAR _8 =
        NATURALINNERJOIN (
            'Table 1',
            SUMMARIZE ( UNION ( _6, _7 ), [Local Product Group Unit], [Supplier] )
        )
    RETURN
        _8
    

     

     

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

      Can we use a measure as a visual level filter?

       

      Where

      runningPct =
      VAR GroupSummary =
          ADDCOLUMNS (
              CALCULATETABLE (
                  SUMMARIZE (
                      'Table 1',
                      'Table 1'[Local Product Group Unit],
                      'Table 1'[Supplier]
                  ),
                  REMOVEFILTERS ( 'Table 1'[Supplier] )
              ),
              "@pct", [pct]
          )
      VAR CurrPct = [pct]
      RETURN
          SUMX ( FILTER ( GroupSummary, [@pct] >= CurrPct ), [@pct] )

       

  • Anonymous not fully clear what you are looking for. can you provide an example of the output?

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      parry2k The calcuation measures that you provided are correct. My current requirement is as you can see in the attached picture i.e. whatsoever Suppliers get filtered as Top N%(Ex: Top 60%), I can get a sum of their count in a new column as shown in the attached picture and this Sum of their count must come from Number Supplier Orders column of Table1 as for each distinct Supplier in the Supplier Column there is a value "1" in Number Supplier Orders column of Table1(Please Refer Table1 data)

  • Anonymous Given the data, is this the expected output