Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
nikos_derv
Frequent Visitor

Column flag for top percentage

Hello,

 

I need to create a calculated column where it crates a flag (yes/no) for the top 10% per category. Any saggestions? 

 

To be more precise, i need to flag in a customer per store dataset, the top 10% customers per store, based on their spending.

 

Many thanks in advance!

2 REPLIES 2
danextian
Super User
Super User

Hi @nikos_derv ,

 

This can by creating several calculated  columns but a warning, this looping in each row per category and can be very slow on  large table. I'd like to see a more efficient to this approach if there is.

 

 

Percentage = 
//value percentage within a category
VAR CategoryTotal =
    CALCULATE (
        SUM ( 'DataTable'[Values] ),
        ALLEXCEPT ( 'DataTable', 'DataTable'[Category] )
    )
RETURN
    DIVIDE ( 'DataTable'[Values], CategoryTotal )
Percentage Rank within a category = 
//rank the percentage with highest as one
RANKX (
    FILTER (
        'DataTable',
        'DataTable'[Category] = EARLIER ( 'DataTable'[Category] )
    ),
    'DataTable'[Values],
    ,
    DESC,
    DENSE
)

 

The formula below can be very slow - might cause memory crash/webview2 error/bluescreen error.

 

Top10 =
//calculates the runninng percentage based on the rank and by category
//returns true if the running percentage is <= 10%
CALCULATE (
    SUM ( 'DataTable'[Percentage] ),
    FILTER (
        FILTER (
            'DataTable',
            'DataTable'[Category] = EARLIER ( 'DataTable'[Category] )
        ),
        'DataTable'[Percentage Rank within a category]
            <= EARLIER ( 'DataTable'[Percentage Rank within a category] )
    )
) <= .10

 

danextian_0-1678285605687.png

Please refer to the attached pbix. Go to the dataview then select Datatable table

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thank you @danextian for your reply!

I didn't get to use exactly your suggestion but you definately showed me the right direction.

 

In case anyone else might have the same issue, my solution was: 

-create a column to calculate rank per category, using RankX (as mentioned above)

-create a column to calculate the max value of rank column, for each category 

-final flag column: IF('rank column' <0.1 'max rank per category column' ,1,0)
 
Again, many thanks for our support!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.