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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
prof_hoo
Frequent Visitor

Find row value based on two other columns

I want to find the type based on a numeric column for each state. Here is an brief example of the data I have. I have a location column (State), a category column (Type), and a value column. For each state, I want the type with the highest value for all of the types for that state. E.g., type Z in Alabama has the highest value (4), so I want to display Z. Overall, however, the type with the highest sum is Y, so if my slicer  is set to "all" I want Y.

 

StateTypeValue
AlabamaW1
AlabamaX2
AlabamaY3
AlabamaZ4
CaliforniaW5
CaliforniaX3
CaliforniaY4
CaliforniaZ1
VermontX1
VermontY1
VermontZ2

 

For Alabama, my card should display "Z", for California , "W", for Vermont, "Z", and for all "Y".

 

I think I could do this by creating new tables, but I'm new to PBI and I'm trying to avoid that crutch. 

 

Thanks so much!

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@prof_hoo Try this measure, change table and column name as per your model

 

Top Type = 
CALCULATE ( 
    MAX ( HighType[Type] ),
    TOPN (
        1, 
        ALLSELECTED ( HighType[Type] ),
        CALCULATE ( SUM ( HighType[Value] ) ),
        DESC
    )
)

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

9 REPLIES 9
parry2k
Super User
Super User

@prof_hoo Try this measure, change table and column name as per your model

 

Top Type = 
CALCULATE ( 
    MAX ( HighType[Type] ),
    TOPN (
        1, 
        ALLSELECTED ( HighType[Type] ),
        CALCULATE ( SUM ( HighType[Value] ) ),
        DESC
    )
)

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@prof_hoo now it makes a bit of sense, but why 'Y' for all, what is the logic behind that, or if more than one state is selected it will be 'Y'

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Because if you sum up all 4 types, W = 6, X = 6, Y = 8, and Z = 7, so overall, Y is the the type with the highest value.

 

parry2k
Super User
Super User

@prof_hoo you can simply add a column in your table using following DAX expression and then use it in the visuals:

 

New Type = 
VAR __state = Table[State]
RETURN
SWITCH ( __state, 
   "California", "W",
   "Vermont", "Z",
   "Alabama", "Z",
   "Y"
)

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

This isn't the real data; the actual data is much larger and is constantly changing, so hard-coding a solution doesn't work. Thanks though!

@prof_hoo I don't understand what do you mean by hardcoding, you provided the logic and the solution is based on your ask.

 

You need to provide more details to explain the logic so that community can provide you the help. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Apologies; I edited my post to better explain the logic I'm looking to create.

davehus
Memorable Member
Memorable Member

Hi @prof_hoo , Can you provide an example of the desired result?

 

Thanks.

 

Did I help you today? Please accept my solution and hit the Kudos button.

There is a card which should show the appropriate type depending on the selection in the slicer. 

 

For Alabama, my card should display "Z"; for California , "W"; for Vermont, "Z"; and for all "Y".

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.