Forum Discussion

PBINewbie920's avatar
PBINewbie920
Helper I
3 years ago
Solved

Create Most Often field

Hi Everyone,

 

My data curretly looks like this: 

 

CustomerColor
Customer ARed
Customer ARed
Customer ARed
Customer ARed
Customer AOrange
Customer AGreen
Customer ABlue
Customer APink
Customer APink
Customer APurple
Customer BRed
Customer BOrange
Customer BYellow
Customer BYellow
Customer BYellow

 

 

My goal is to summarize it in PBI to look like this: 

 

CustomerPrimary ColorPrimary Color %
Customer ARed40%
Customer BYellow60%

 

Any thoughts how I can do this? I cant figure out a way to get the most often and the percent related to it,

 

Any input would be appreciated!!

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi PBINewbie920 ,

    Please try these measures:

     

    Primary Color % = 
    VAR _customer = MAX('Table'[Customer])
    VAR _color = MAX('Table'[Color])
    VAR _count =
        CALCULATE (
            COUNT ( 'Table'[Customer] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Customer] = _customer
                    && 'Table'[Color] = _color
            )
        )
    VAR _count_all =
        CALCULATE (
            COUNT ( 'Table'[Customer] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Customer] = _customer )
        )
    VAR _rate =
        DIVIDE ( _count, _count_all )
    RETURN
        _rate
    Filter = 
    VAR _max = MAXX(ALLEXCEPT('Table','Table'[Customer]),[Primary Color %])
    VAR _result = IF([Primary Color %]=_max,1)
    RETURN
    _result

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly -- How to provide sample data

7 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    PBINewbie920 Maybe:

    Primary Color Measure =
      VAR __Table = SUMMARIZE('Table',[Customer],[Color],"__Count",COUNTROWS('Table')
      VAR __Max = MAXX(__Table,[__Count])
    RETURN
      MAXX(FILTER(__Table,[__Count]=__Max),[Color])
    
    and you can also do this:
    Primary Color % =
      VAR __Total = COUNTROWS('Table')
      VAR __Color = [Primary Color Measure]
      VAR __Count = COUNTROWS(FILTER('Table',[Color] = __Color)
    RETURN
      DIVIDE(__Count, __Total, 0)
    • PBINewbie920's avatar
      PBINewbie920
      Helper I

      Greg_Deckler Hi! thank you!! I tried to use this in DAX as a column, and as a created measure, but both ways I keep getting an error:

       

       

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        PBINewbie920 Missed a closing paren:

        Primary Color Measure =
          VAR __Table = SUMMARIZE('Table',[Customer],[Color],"__Count",COUNTROWS('Table'))
          VAR __Max = MAXX(__Table,[__Count])
        RETURN
          MAXX(FILTER(__Table,[__Count]=__Max),[Color])
        
    • PBINewbie920's avatar
      PBINewbie920
      Helper I

      tackytechtom Thank you! I gave this a try and it looks like something is off, its not giving me the top result but just showing me all the options?

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi PBINewbie920 ,

    Please try these measures:

     

    Primary Color % = 
    VAR _customer = MAX('Table'[Customer])
    VAR _color = MAX('Table'[Color])
    VAR _count =
        CALCULATE (
            COUNT ( 'Table'[Customer] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Customer] = _customer
                    && 'Table'[Color] = _color
            )
        )
    VAR _count_all =
        CALCULATE (
            COUNT ( 'Table'[Customer] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Customer] = _customer )
        )
    VAR _rate =
        DIVIDE ( _count, _count_all )
    RETURN
        _rate
    Filter = 
    VAR _max = MAXX(ALLEXCEPT('Table','Table'[Customer]),[Primary Color %])
    VAR _result = IF([Primary Color %]=_max,1)
    RETURN
    _result

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly -- How to provide sample data