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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
WestWinter
Helper II
Helper II

How to calculate which percentile the latest value is in against other values in same category?

So I have the below table, and would like to get a formula to find out which percentile my latest value (in this case, the 1/4/2020) is in. How can I find this?

 

DateCategoryValue
1/1/2020A34214
1/2/2020A209319
1/3/2020A39420
1/4/2020A2330
1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @WestWinter ,

 

I created a calculated column to calculate the percentile.

Column =
VAR _ROW1 =
    CALCULATE (
        COUNTROWS ( Table1 ),
        FILTER (
            Table1,
            Table1[Value] <= EARLIER ( Table1[Value] )
                && Table1[Category] = EARLIER ( Table1[Category] )
        )
    )
VAR _ROW2 =
    CALCULATE ( COUNTROWS ( Table1 ), ALLEXCEPT ( Table1, Table1[Category] ) )
VAR _P = _ROW1 / _ROW2
VAR MAX_DATE =
    CALCULATE ( MAX ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[Category] ) )
RETURN
    IF ( Table1[Date] = MAX_DATE, _P )

Sample .pbix

 

Best Regards,
Liang
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

6 REPLIES 6
V-lianl-msft
Community Support
Community Support

Hi @WestWinter ,

 

I created a calculated column to calculate the percentile.

Column =
VAR _ROW1 =
    CALCULATE (
        COUNTROWS ( Table1 ),
        FILTER (
            Table1,
            Table1[Value] <= EARLIER ( Table1[Value] )
                && Table1[Category] = EARLIER ( Table1[Category] )
        )
    )
VAR _ROW2 =
    CALCULATE ( COUNTROWS ( Table1 ), ALLEXCEPT ( Table1, Table1[Category] ) )
VAR _P = _ROW1 / _ROW2
VAR MAX_DATE =
    CALCULATE ( MAX ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[Category] ) )
RETURN
    IF ( Table1[Date] = MAX_DATE, _P )

Sample .pbix

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@WestWinter ,

Try like divide(lastnonblankvalue(Table[Date],sum(Table[Value])),sum(Table[Value]))

 

Plot against category

for date use max or lastnonblank or last

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Fowmy
Super User
Super User

@WestWinter 

Do you also need the percentile per category?

Thanks

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

No. Just how the latest value (or all values) fair against all other values in the same category.

@WestWinter

 

Percentile Latest Value = 

VAR _DATE = CALCULATE(MAX(TABLE01[Date]),ALL(TABLE01))
VAR _VALUE = CALCULATE( SUM(TABLE01[Value]), TABLE01[Date] = _DATE, ALL(TABLE01)) 
    
RETURN
COALESCE(
    DIVIDE(
        CALCULATE(
            COUNTROWS(TABLE01),
            FILTER(
                ALL(TABLE01),
                TABLE01[Value] < _VALUE
            )
        ),

            COUNTROWS(ALL(TABLE01))
    )
    ,0
)

 



You can use per row dynamic measure as below:

Percentile Latest Value Per Row = 

VAR _VALUE = SUM(TABLE01[Value])

RETURN
COALESCE(
    DIVIDE(
        CALCULATE(
            COUNTROWS(TABLE01),
            FILTER(
                ALL(TABLE01),
                TABLE01[Value] < _VALUE
            )
        ),

            COUNTROWS(ALL(TABLE01))
    )
    ,0
)

 

 

Fowmy_0-1596781326834.png

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

I tried your DAX code for my measure, but it returned me all 1.00 for all categories... strange

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.