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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
lisago1978
Helper III
Helper III

Creating percentile tiers that can be mapped in Power BI

i need some help, I was able to create new measures that correctly gave me percentiles of my summary data, but I don't know how I can then map this as "tiers" on a shape map since it is not a column rather it is a "measure"

 

1. First, I grouped(summarized) my data using Power Query. Here is the M code

 


let
Source = Value.NativeQuery(PostgreSQL.Database("data-is.acphd.us:45432", "cape", [CreateNavigationProperties=false]), "SELECT * FROM inquiries_log_view_v2", null, [EnableFolding=true]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date/Time of Call", type datetime}}),
#"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"Entry ID", "Inquirer City of Residence"}),
#"Grouped Rows" = Table.Group(#"Removed Other Columns", {"Inquirer City of Residence"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
#"Grouped Rows"

 

Here is the table

City of ResidenceCount
Alameda380
Albany54
Ashland1
Berkeley163
Castro Valley119
Cherryland1
Did Not Provide3224
Dublin203
Emeryville57
Fairview1
Fremont535
Hayward515
Livermore391

 

2. Then, I started creating my new measures for each tertile (.75, .5, and .5)

 

_25_Percentile = CALCULATE(PERCENTILEX.INC('Location', [Count],0.25), ALL('Location'[Inquirer City of Residence]))
_50_Percentile = CALCULATE(PERCENTILEX.INC('Location', [Count],0.50), ALL('Location'[Inquirer City of Residence]))
_75_Percentile = CALCULATE(PERCENTILEX.INC('Location', [Count],0.75), ALL('Location'[Inquirer City of Residence]))

 

 

3. Next, I created my tiers based on these percentiles using if statements

 

Tier = IF([_Count]<=[_25_Percentile],"Low",(IF(AND([_Count]<=[_50_Percentile],[_Count]>[_25_Percentile]),"Medium","Hgh")))

 

When I use the matrix visual feature all of these measures work, but I cannot figure out how to transition to a map based on city/place where I can shade based on tier since these are dynamic measures.

 

Here is my matrix Power BI visual. 

 

City of ResidenceCount_25_Percentile_50 Percentile_75 PercentileTier
Alameda38028123.5382.75Hgh
Albany5428123.5382.75Medium
Ashland128123.5382.75Low
Berkeley16328123.5382.75Hgh
Castro Valley11928123.5382.75Medium
Cherryland128123.5382.75Low
Did Not Provide322428123.5382.75Hgh
Dublin20328123.5382.75Hgh
Emeryville5728123.5382.75Medium
Fairview128123.5382.75Low
Fremont53528123.5382.75Hgh
Hayward51528123.5382.75Hgh
Livermore39128123.5382.75Hgh


One assumption I have is that a table needs to be created that can be viewed in table views that shows low, medium and high in rows on a summary table, but since these are dynamic, I don't know how to do that.

 

8 REPLIES 8
v-lionel-msft
Community Support
Community Support

Hi @lisago1978 ,

 

Like this?

v-lionel-msft_0-1598247368959.png

Your address([City of Residence] column) is not detailed enough to draw a map, try to add country and state.

 

Best regards,
Lionel Chen

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

 

 

Yes, I just changed the category type to City andit worked. Thank you for responding!

@lisago1978 - was the measure I provided able to get you up and running? Do you have the final solution? If so, could you mark the post(s) that solved this for you as the solution so it can be shown to have an answer? If not, can you post back with what you lack in getting this working?



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thanks, I did try this, but it was still showing all tiers as highest or 4 in my matrix. The formula seems to work though not sure why it isn't showing it. I decided to go with some pre-set tiers based on categories so that I could complete this.

lisago1978
Helper III
Helper III

Sorry, I did the formula wrong, I added this formula into the table I have in Power BI as a calculated column. It computed Highest for every row, for some reason.

 

Test2 =
IF('Location'[Count]<[_25_Percentile],1,
IF(AND('Location'[Count]<[_50_Percentile],'Location'[Count]>=[_25_Percentile]),2,
IF(AND('Location'[Count]<[_75_Percentile], 'Location'[Count]>=[_50_Percentile]),3,
IF('Location'[Count]>=[_75_Percentile],4))))

Hi @lisago1978 - is this what you need?

edhans_0-1598053558665.png

If so, this is the measure.

 

Test2 = 
VAR varCurrentLocationCount =
    MAX( Location[Count] )
RETURN
    SWITCH(
        TRUE(),
        varCurrentLocationCount < [_25_Percentile], 1,
        varCurrentLocationCount < [_50_Percentile]
            && varCurrentLocationCount >= [_25_Percentile], 2,
        varCurrentLocationCount < [_75_Percentile]
            && varCurrentLocationCount >= [_50_Percentile], 3,
        4
    )

 

Also, I don't know your data, so this suggestion may be wrong, but I suggest this instead:

 

Test2 = 
VAR varCurrentLocationCount =
    MAX( Location[Count] )
RETURN
    SWITCH(
        TRUE(),
        varCurrentLocationCount <= [_25_Percentile], 1,
        varCurrentLocationCount <= [_50_Percentile]
            && varCurrentLocationCount > [_25_Percentile], 2,
        varCurrentLocationCount <= [_75_Percentile]
            && varCurrentLocationCount > [_50_Percentile], 3,
        4
    )

 

If it is equal to the 25th percentile, the 2nd code sample will put it in the 25th percentile, or 1. Your original logic would have bumped it to the 2nd percentile, or 2. That might be right, it just looked odd to me and thought I would bring it up. You can see that in the Albany result. It is 54, the 1st percentile, but the logic put it in the 2nd. My 2nd measure above keeps it in the 1st group.

 

Note that this is a measure, and should work for you. In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:
Calculated Columns vs Measures in DAX
Calculated Columns and Measures in DAX
Storage differences between calculated columns and calculated tables

If this still isn't the answer you are looking for, ping back with more info and expected results.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thank you I will try this. THe only reason I went with calculated columns in DAX was so that I could map this in tiers on the Power BI shape map. In general, any calculations I am doing, I try to do using the measures in DAX.

Understood. You can use measures in that filed in the Shape Map, so hopefully this works. Ping back with questions, or mark it as solved.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.