Forum Discussion
DAX - Most Frequent value
Hi,
I would like to find the most frequenct value(most repeated times) by DAX. May I know is it possible?
Original Table
| Item | ID | user |
| 1 | 1 | Peter |
| 1 | 2 | Peter |
| 1 | 3 | Alex |
| 1 | 4 | Peter |
| 1 | 5 | Chris |
| 1 | 6 | Chris |
| 2 | 1 | Alex |
| 2 | 2 | Alex |
| 2 | 3 | Peter |
Desired Result:
| Item | Most Frequency |
| 1 | Peter |
| 2 | Alex |
Hi,
To your Table visual, drag the Item field and write these mesures
User count = counta(Data[User])
Most frequency = FIRSTNONBLANK(TOPN(1,VALUES(Data[User]),[User count]),1)
Drag the second measure to your visual.
22 Replies
- Ashish_MathurSuper User
Hi,
To your Table visual, drag the Item field and write these mesures
User count = counta(Data[User])
Most frequency = FIRSTNONBLANK(TOPN(1,VALUES(Data[User]),[User count]),1)
Drag the second measure to your visual.
- ngct1112Post Patron
Ashish_Mathur Thanks Ashish, it works fine in my model. Appreciated.
- Ashish_MathurSuper User
You are welcome. If my previous reply helped, please mark that as Answer.
- ngct1112Post Patron
Hi Ashish_Mathur , may I have a futher question regarding this formula?
Is it possible I could add a filter in your formula like filter "group" = "B"Appreciated if you could help
Original:
Item ID user group 1 1 Peter A 1 2 Peter A 1 3 Alex A 1 4 Peter B 1 5 Chris B 1 6 Chris B 2 1 Alex A 2 2 Alex A 2 3 Peter B Desired result:
Item Mast Frequent(B) 1 Chris 2 Peter - Ashish_MathurSuper User
Hi,
This measure works
Most frequent = CALCULATE(FIRSTNONBLANK(TOPN(1,VALUES(Data[User]),[User count],DESC),1),Data[group]="B")Hope this helps.
- Khaled2023Frequent Visitor
Hi,
How can I get the number (how many times repeated the most frequent value).
I'd like to display it in a card.
Thanks
- Ashish_MathurSuper User
Hi,
Write the formula suggested in my message. If t does not work, then share some data to work with, explain the question and show the expected result.
- Jihwan_KimSuper User
Most Frequent User : =
VAR _userstable =
RELATEDTABLE ( Data )
VAR _groupbyusers =
GROUPBY ( _userstable, Users[user], "@count", SUMX ( CURRENTGROUP (), 1 ) )
VAR _maxcount =
MAXX ( _groupbyusers, [@count] )
VAR _maxcountuserlist =
SUMMARIZE ( FILTER ( _groupbyusers, [@count] = _maxcount ), Users[user] )
RETURN
IF (
HASONEVALUE ( Items[Item] ),
IF ( COUNTROWS ( _maxcountuserlist ) = 1, _maxcountuserlist )
)- ngct1112Post Patron
Jihwan_Kim Thanks for your solutions!