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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PBINewbie920
Helper I
Helper I

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

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

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

vcgaomsft_1-1664262156706.png

 

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

View solution in original post

7 REPLIES 7
v-cgao-msft
Community Support
Community Support

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

vcgaomsft_1-1664262156706.png

 

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

tackytechtom
Super User
Super User

Hi @PBINewbie920 ,

 

Here a possible solution:

tomfox_0-1664225910172.png

 

Here my three measures:

CountMeasure = COUNTROWS ( 'Table' )
TopCountMeasure = 
CONCATENATEX ( 
    TOPN ( 
        1, 
        VALUES ( 'Table'[Color] ), 
        [CountMeasure]
    ), 
    'Table'[Color], ", "
)
PercentageMeasure = 
DIVIDE ( 
    MAXX ( 
        VALUES ( 'Table'[Color] ), 
        [CountMeasure] 
    ), 
    [CountMeasure] 
) 

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

@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?

PBINewbie920_1-1664227619534.png

 

Greg_Deckler
Super User
Super User

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

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@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:

 

PBINewbie920_0-1664226202431.png

 

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

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thanks! Looks like its not able to distinguish between the different Customers-- like customer B should be yellow. However it looks like its just picking the top from color in general:

 

PBINewbie920_0-1664227490273.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.