Forum Discussion

ngct1112's avatar
ngct1112
Post Patron
5 years ago
Solved

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

ItemIDuser
11Peter
12Peter
13Alex
14Peter
15Chris
16Chris
21Alex
22Alex
23Peter

 

Desired Result:

ItemMost Frequency
1Peter
2Alex
  • 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

  • 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.

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        You are welcome.  If my previous reply helped, please mark that as Answer.

    • ngct1112's avatar
      ngct1112
      Post 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:

      ItemIDusergroup
      11PeterA
      12PeterA
      13AlexA
      14PeterB
      15ChrisB
      16ChrisB
      21AlexA
      22AlexA
      23PeterB

       

       

      Desired result:

      ItemMast Frequent(B)
      1Chris
      2Peter
      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Hi,

        This measure works

        Most frequent = CALCULATE(FIRSTNONBLANK(TOPN(1,VALUES(Data[User]),[User count],DESC),1),Data[group]="B")

        Hope this helps.

    • Khaled2023's avatar
      Khaled2023
      Frequent 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_Mathur's avatar
        Ashish_Mathur
        Super 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.

  •  

    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 )
    )

     

     

    Link to the pbix file