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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

top 3 columns for each zip code

Hello, My data is as follows:  

IDNAMEINDBANGLBHUTNBURMSCAMBDCHINS
47616Griffin000000
47620Mount Vernon11000015
47631New Harmony000000
47633Poseyville100003
47638Wadesville200003
47665Owensville100005
46164Nineveh200001
47001Aurora100004
47006Batesville50000017
47011Bennington000000
47017Cross Plains100000
47018Dillsboro200001
47020Florence100000
47021Friendship000000
47022Guilford100003

I am trying to plot a table as follows:

IDNameTop1 value & Name of columnTop2 &
Name of column
Top3 & Name of column
47631New Harmony   
47633Poseyville   
47638Wadesville   
47665Owensville   
46164Nineveh   
47001Aurora   
1 ACCEPTED SOLUTION
smpa01
Community Champion
Community Champion

@Anonymous  for a stater you need to unpivot the table. Also the data provided here is not suitable for TOPN filtering cause the top 3 values are 0,1,>1 for any given ID.  In this TOPN(3) would return all the values

 

But let's suppose you had a table like following and you had it unpivoted

 

| ID    | NAME         | IND | BANGL | BHUTN | BURMS | CAMBD | CHINS |
|-------|--------------|-----|-------|-------|-------|-------|-------|
| 47616 | Griffin      | 102 | 290   | 358   | 360   | 186   | 310   |
| 47620 | Mount Vernon | 339 | 399   | 274   | 305   | 199   | 124   |
| 47631 | New Harmony  | 161 | 276   | 283   | 170   | 336   | 284   |
| 47633 | Poseyville   | 237 | 370   | 300   | 242   | 399   | 292   |
| 47638 | Wadesville   | 355 | 188   | 272   | 259   | 375   | 142   |
| 47665 | Owensville   | 214 | 269   | 335   | 240   | 282   | 326   |
| 46164 | Nineveh      | 171 | 158   | 335   | 329   | 218   | 376   |
| 47001 | Aurora       | 207 | 393   | 223   | 256   | 311   | 212   |
| 47006 | Batesville   | 378 | 364   | 327   | 197   | 152   | 184   |
| 47011 | Bennington   | 200 | 298   | 153   | 116   | 307   | 158   |
| 47017 | Cross Plains | 151 | 175   | 300   | 266   | 365   | 292   |
| 47018 | Dillsboro    | 270 | 376   | 310   | 281   | 310   | 311   |
| 47020 | Florence     | 361 | 251   | 388   | 225   | 364   | 108   |
| 47021 | Friendship   | 229 | 305   | 261   | 191   | 328   | 163   |
| 47022 | Guilford     | 397 | 151   | 331   | 200   | 317   | 312   |

 

you can write following two measures to give you what you need

_sum = SUM('Table 1'[Value])

Measure = 
VAR _id =
    MAX ( 'Table 1'[ID] )
RETURN
    CALCULATE (
        [_sum],
        KEEPFILTERS (
            TOPN (
                3,
                FILTER ( ALLSELECTED ( 'Table 1' ), 'Table 1'[ID] = _id ),
                [_sum], DESC
            )
        )
    )

 

 

smpa01_0-1640878411722.png

 

  

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

1 REPLY 1
smpa01
Community Champion
Community Champion

@Anonymous  for a stater you need to unpivot the table. Also the data provided here is not suitable for TOPN filtering cause the top 3 values are 0,1,>1 for any given ID.  In this TOPN(3) would return all the values

 

But let's suppose you had a table like following and you had it unpivoted

 

| ID    | NAME         | IND | BANGL | BHUTN | BURMS | CAMBD | CHINS |
|-------|--------------|-----|-------|-------|-------|-------|-------|
| 47616 | Griffin      | 102 | 290   | 358   | 360   | 186   | 310   |
| 47620 | Mount Vernon | 339 | 399   | 274   | 305   | 199   | 124   |
| 47631 | New Harmony  | 161 | 276   | 283   | 170   | 336   | 284   |
| 47633 | Poseyville   | 237 | 370   | 300   | 242   | 399   | 292   |
| 47638 | Wadesville   | 355 | 188   | 272   | 259   | 375   | 142   |
| 47665 | Owensville   | 214 | 269   | 335   | 240   | 282   | 326   |
| 46164 | Nineveh      | 171 | 158   | 335   | 329   | 218   | 376   |
| 47001 | Aurora       | 207 | 393   | 223   | 256   | 311   | 212   |
| 47006 | Batesville   | 378 | 364   | 327   | 197   | 152   | 184   |
| 47011 | Bennington   | 200 | 298   | 153   | 116   | 307   | 158   |
| 47017 | Cross Plains | 151 | 175   | 300   | 266   | 365   | 292   |
| 47018 | Dillsboro    | 270 | 376   | 310   | 281   | 310   | 311   |
| 47020 | Florence     | 361 | 251   | 388   | 225   | 364   | 108   |
| 47021 | Friendship   | 229 | 305   | 261   | 191   | 328   | 163   |
| 47022 | Guilford     | 397 | 151   | 331   | 200   | 317   | 312   |

 

you can write following two measures to give you what you need

_sum = SUM('Table 1'[Value])

Measure = 
VAR _id =
    MAX ( 'Table 1'[ID] )
RETURN
    CALCULATE (
        [_sum],
        KEEPFILTERS (
            TOPN (
                3,
                FILTER ( ALLSELECTED ( 'Table 1' ), 'Table 1'[ID] = _id ),
                [_sum], DESC
            )
        )
    )

 

 

smpa01_0-1640878411722.png

 

  

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

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

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.