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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
cristianj
Helper IV
Helper IV

calculate top XX% from a table for each day

hello, i have a table in which for each day i have the Sales % for each product, something like:

Date | Product | Sale for that day for that product | % Sale for that day for that product from total sales for that day|

I want to make a formula, in a column which return 3 values for each day, for each product, if the product sale Procent is in the top 70% the value should be tier1, is it is in the 70% from the last 30% from total it would say tier2 and blank for the rest

something like that.

Thank you

dayproduct sales that day  total sales that day  %from total  Tier 
01.01.2023 Product05  30 1160.25862069 Tier1
01.01.2023 Product07 271160.232758621Tier1
01.01.2023Product01111160.094827586Tier1
01.01.2023Product09111160.094827586Tier1
01.01.2023Product1091160.077586207Tier2
01.01.2023Product1171160.060344828Tier2
01.01.2023Product0851160.043103448Tier2
01.01.2023Product0351160.043103448 
01.01.2023Product0651160.043103448 
01.01.2023Product0441160.034482759 
01.01.2023Product0221160.017241379 
01.02.2023Product0420840.238095238Tier1
01.02.2023Product0818840.214285714Tier1
01.02.2023Product1014840.166666667Tier1
01.02.2023Product116840.071428571Tier1
01.02.2023Product095840.05952381Tier2
01.02.2023Product025840.05952381Tier2
01.02.2023Product015840.05952381Tier2
01.02.2023Product054840.047619048 
01.02.2023Product033840.035714286 
01.02.2023Product063840.035714286 
01.02.2023Product071840.011904762 
01.03.2023Product08261290.201550388Tier1
01.03.2023Product06251290.19379845Tier1
01.03.2023Product09141290.108527132Tier1
01.03.2023Product11121290.093023256Tier1
01.03.2023Product01121290.093023256Tier1
01.03.2023Product05111290.085271318Tier2
01.03.2023Product10111290.085271318Tier2
01.03.2023Product0291290.069767442 
01.03.2023Product0451290.03875969 
01.03.2023Product0331290.023255814 
01.03.2023Product0711290.007751938 

 

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @cristianj ,

I created a sample pbix file(see the attachment), please find the details in it.

By measures:

rank = 
VAR _seldate =
    SELECTEDVALUE ( 'Table'[day] )
RETURN
    RANKX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[day] = _seldate ),
        CALCULATE ( MAX ( 'Table'[%from total] ) ),
        ,
        DESC,
        DENSE
    )
Tier = 
VAR _seldate =
    SELECTEDVALUE ( 'Table'[day] )
VAR _maxrank =
    MAXX ( FILTER ( ALLSELECTED ( 'Table' ), 'Table'[day] = _seldate ), [rank] )
VAR _70perrank =
    ROUND ( _maxrank * 0.7, 0 )
RETURN
    IF (
        [rank] <= _70perrank,
        IF ( [rank] <= _70perrank * 0.7, "Tier1", "Tier2" ),
        BLANK ()
    )

By calculated columns:

Column = 
RANKX (
    FILTER ( 'Table', 'Table'[day] = EARLIER ( 'Table'[day] ) ),
    'Table'[%from total],
    ,
    DESC,
    DENSE
)
Column 2 = 
VAR _maxrank =
    MAXX ( FILTER ( 'Table', 'Table'[day] = EARLIER ( 'Table'[day] ) ), [Column] )
VAR _70perrank =
    ROUND ( _maxrank * 0.7, 0 )
RETURN
    IF (
        [Column] <= _70perrank,
        IF ( [Column] <= _70perrank * 0.7, "Tier1", "Tier2" ),
        BLANK ()
    )

vyiruanmsft_0-1682917637412.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @cristianj ,

I created a sample pbix file(see the attachment), please find the details in it.

By measures:

rank = 
VAR _seldate =
    SELECTEDVALUE ( 'Table'[day] )
RETURN
    RANKX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[day] = _seldate ),
        CALCULATE ( MAX ( 'Table'[%from total] ) ),
        ,
        DESC,
        DENSE
    )
Tier = 
VAR _seldate =
    SELECTEDVALUE ( 'Table'[day] )
VAR _maxrank =
    MAXX ( FILTER ( ALLSELECTED ( 'Table' ), 'Table'[day] = _seldate ), [rank] )
VAR _70perrank =
    ROUND ( _maxrank * 0.7, 0 )
RETURN
    IF (
        [rank] <= _70perrank,
        IF ( [rank] <= _70perrank * 0.7, "Tier1", "Tier2" ),
        BLANK ()
    )

By calculated columns:

Column = 
RANKX (
    FILTER ( 'Table', 'Table'[day] = EARLIER ( 'Table'[day] ) ),
    'Table'[%from total],
    ,
    DESC,
    DENSE
)
Column 2 = 
VAR _maxrank =
    MAXX ( FILTER ( 'Table', 'Table'[day] = EARLIER ( 'Table'[day] ) ), [Column] )
VAR _70perrank =
    ROUND ( _maxrank * 0.7, 0 )
RETURN
    IF (
        [Column] <= _70perrank,
        IF ( [Column] <= _70perrank * 0.7, "Tier1", "Tier2" ),
        BLANK ()
    )

vyiruanmsft_0-1682917637412.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.