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
FrancescaLu
Frequent Visitor

DAX - Retrieve a value in one column for max occurence of distinct values based on another column

Hi,

 

First post, sorry for the confusing subject, in fact i'm really struggling to find a solution. Hopefully, somebody could help me find the correct DAX statement.

 

My goal is to have a column with the value of another column associated to the max occurence of distinct values based on another column. I can explain better with an example.

My set of data is something like this table:

 

IDValueColumn1
A3X
A3X
A3X
B1X
C1X
D2Y
E4Y
E4Y
F2Y

What I want is to select "Value" associated to the max number of different ID, and I want to do this for each different value of "Column1", so the result has to be like this:

IDValueColumn1Result
A3X1
A3X1
A3X1
B1X1
C1X1
D2Y2
E4Y2
E4Y2
F2Y2

 

Please, advise if not clear enough.

 

Thank you a lot!

 

 

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @FrancescaLu ,

 

Please check below formulas.

count_ = CALCULATE(DISTINCTCOUNT('Table'[ID]),ALLEXCEPT('Table','Table'[Value],'Table'[Column1]))

Measure = 
var max_ = MAXX(ALLEXCEPT('Table','Table'[Column1]),[count_])
return
CALCULATE(MAX('Table'[Value]),FILTER(ALLEXCEPT('Table','Table'[Column1]),[count_]=max_))

vjaywmsft_0-1658209555256.png

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

7 REPLIES 7
v-jayw-msft
Community Support
Community Support

Hi @FrancescaLu ,

 

Please check below formulas.

count_ = CALCULATE(DISTINCTCOUNT('Table'[ID]),ALLEXCEPT('Table','Table'[Value],'Table'[Column1]))

Measure = 
var max_ = MAXX(ALLEXCEPT('Table','Table'[Column1]),[count_])
return
CALCULATE(MAX('Table'[Value]),FILTER(ALLEXCEPT('Table','Table'[Column1]),[count_]=max_))

vjaywmsft_0-1658209555256.png

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Thank you @v-jayw-msft, this is a real good solution, but i need the result displayed in a new column contained in the table. The problem is that with a measure i can only see it on dashboards.

Hi @FrancescaLu ,

 

The above formulas also work for calculated column.

vjaywmsft_0-1658284643527.png

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
parry2k
Super User
Super User

sorry, I'm still not very clear about what you are trying to achieve. Maybe it's me



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.

I try to explain with other words. I want to retrieve for each value of Column1, the value contained in "Value" that recurs the maximum number of times for different ID

parry2k
Super User
Super User

@FrancescaLu not really clear, why the max number for A will be 1, what you are referring to as number?

 

 



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.

Hi, thank you fir answering!

I would put 1 also for A becouse for X i got A with value 3, but it appearse only one time. Instead, value 1 appearse 2 times, with B and C.

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.