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