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
Anonymous
Not applicable

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 

sha009_2-1640096750089.png

 

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

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

18 REPLIES 18
parry2k
Super User
Super User

@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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

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

parry2k
Super User
Super User

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

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

T2.0.jpg

@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)

parry2k
Super User
Super User

@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.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.

T11.jpg

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.

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.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
parry2k
Super User
Super User

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

 

2021-12-21_12-45-57.gif



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Anonymous Given the data, is this the expected output

 

parry2k_0-1640115901793.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

smpa01
Super User
Super User

@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

 

smpa01_0-1640113917879.png

 

 

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

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Can we use a measure as a visual level filter?

AlexisOlson_0-1640119027709.png

 

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] )

 

smpa01
Super User
Super User

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

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
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).

@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

smpa01_0-1640101758135.png

 

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%

 

smpa01_1-1640102341325.png

 

Please confirm

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

Once SUM of Order Value USD BR is done by Distinct Local Product Group Unit, We need to Filter Out All those "Suppliers" from Supplier column which covered Top 60% portion of SUM of Order Value USD BR by Distinct Local Product Group Unit 

@Anonymous  so what is the desired output for the given dataset?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

A table as that shown in the attached screenshot should be implemented as Power BI table(or Matrix) visual. Basically, implementing the filter as shown in the attached screenshot and applying it to table(or Matrix) visual.

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.

Top Solution Authors