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
hawb
Helper I
Helper I

Creating Dynamic Equal Bins (using percentile.inc)

 
1.) I have a table containing columns for Fish Species and Length. e.g.
Bluegill 7.7
Bluegill 8.2
Bluegill 13.2
Crappie 7
Crappie 8.2
Crappe 10.3
 
2.) I want to be able to generate a column in my table that will categorize equally sized "Bins" (i.e. quintiles) BY FISH SPECIES.
 
I found a good reference for how to do this here.
 
The problem in this example is that it generates the bins across the entire dataset instead of by Fish Species. How can I dynamically generate these values based on species?
 
Here is my Dax script
EqualBinsBySpecies =
--Quintiles
VAR N = 5
VAR Percentiles =
ADDCOLUMNS (GENERATESERIES( 1, N ),"Percentile", PERCENTILE.INC(page_Summary_SurveyMeasurements[LengthInches], [Value] / N )
)

RETURN
MINX ( FILTER (Percentiles,page_Summary_SurveyMeasurements[LengthInches] <= [Percentile] ), [Value] )
 
1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @hawb ,

 

Try this:

Bucket = 
VAR N = 5
VAR Percentiles =
    ADDCOLUMNS (
        GENERATESERIES ( 1, N ),
        "Percentile", PERCENTILEx.INC ( FILTER('Table',EARLIER('Table'[Fish Species])='Table'[Fish Species]),'Table'[Length. e.g], [Value] / N )
    )
RETURN
    MINX ( FILTER ( Percentiles, 'Table'[Length. e.g] <= [Percentile] ), [Value] )

V-lianl-msft_0-1602039277828.png

 

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

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

Hi @hawb ,

 

Try this:

Bucket = 
VAR N = 5
VAR Percentiles =
    ADDCOLUMNS (
        GENERATESERIES ( 1, N ),
        "Percentile", PERCENTILEx.INC ( FILTER('Table',EARLIER('Table'[Fish Species])='Table'[Fish Species]),'Table'[Length. e.g], [Value] / N )
    )
RETURN
    MINX ( FILTER ( Percentiles, 'Table'[Length. e.g] <= [Percentile] ), [Value] )

V-lianl-msft_0-1602039277828.png

 

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

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.