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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
1967Maven
New Member

Need a DAX to calculate the Max of string value count

I plan to use a column bar chart to visualize data in the below table in such away that when the Satisfaction_Score is on X Axis, the Y Axis should show ONLY that Satisfaction_Factor which has that max count for that particular Satisfaction_Score (in some cases there might be more than 1 Satisfaction_Factor). 
Help me with a DAX to do this calculation. 

 

 

Customer_IDGroupSatisfaction_ScoreAgeGenderLocationPurchase_HistorySupport_ContactedLoyalty_LevelSatisfaction_FactorLatitudeLongitude
81-237-4704A655MalePhoenix.AZYesNoLowPrice33.4484-112.074
14-117-0504A746FemaleLos Angeles.CAYesNoLowProduct Variety34.0522-118.244
21-336-6416A755FemaleHouston.TXYesYesLowPackaging29.7604-95.3698
59-781-3650A142MaleLos Angeles.CAYesNoMediumPrice34.0522-118.244
52-712-5734B937MaleAustin.TXYesYesMediumPackaging30.2672-97.7431
13-044-3048B952FemalePhiladelphia.PAYesNoMediumPackaging39.9526-75.1652
13-138-2725B960MaleLos Angeles.CANoNoLowEase of Use34.0522-118.244
96-029-4763B828FemalePhoenix.AZYesNoLowProduct Variety33.4484-112.074
74-526-1211B332FemaleAustin.TXNoYesHighEase of Use30.2672-97.7431
66-506-4265A1050FemaleAustin.TXNoYesLowDelivery Speed30.2672-97.7431
53-279-2688B740MaleAustin.TXYesNoLowFeatures30.2672-97.7431
65-115-5317B1049FemaleChicago.ILYesYesLowPrice41.8781-87.6298
61-799-2819A525MaleNew York.NYNoYesMediumProduct Quality40.7128-74.006
14-895-1819B755MaleHouston.TXYesNoHighProduct Quality29.7604-95.3698
04-730-7617B935MaleNew York.NYNoNoHighEase of Use40.7128-74.006
70-262-1283A260MaleNew York.NYNoYesMediumPrice40.7128-74.006
13-111-3439A453FemalePhoenix.AZNoNoLowEase of Use33.4484-112.074
31-562-2114A544FemalePhiladelphia.PANoNoHighCustomer Service39.9526-75.1652
09-982-4228A228MalePhiladelphia.PANoYesMediumFeatures39.9526-75.1652
89-372-9394A247FemaleDallas.TXYesYesLowEase of Use32.7767-96.797
31-456-9342B837FemaleHouston.TXNoNoHighBrand Reputation29.7604-95.3698
23-653-2977A231FemalePhoenix.AZYesNoMediumBrand Reputation33.4484-112.074
73-020-4731B548MalePhoenix.AZNoNoHighPrice33.4484-112.074
60-913-7924B952FemaleHouston.TXYesYesLowFeatures29.7604-95.3698
31-778-0358A457MaleChicago.ILYesYesHighFeatures41.8781-87.6298
67-157-3066A155FemaleSan Antonio.TXYesNoMediumSupport Availability29.4241-98.4936
17-203-6948B151FemaleAustin.TXNoNoLowDelivery Speed30.2672-97.7431
6 REPLIES 6
v-venuppu
Community Support
Community Support

Hi @1967Maven ,

May I ask if you have resolved this issue? Please let us know if you have any further issues, we are happy to help.

Thank you.

v-venuppu
Community Support
Community Support

Hi @1967Maven ,

Thank you for reaching out to Microsoft Fabric Community.

Thank you @MasonMA @Jihwan_Kim @FBergamaschi for the prompt response.

I wanted to check if you had the opportunity to review the information provided and resolve the issue..?Please let us know if you need any further assistance.We are happy to help.

Thank you.

MasonMA
Solution Supplier
Solution Supplier

@1967Maven 

Hi, another simpler approach you may consider would be (I named the table with your sample data 'CustomerFeedback')

1. Create a new table as below. 

FactorCountSummary = 
SUMMARIZE(
    'CustomerFeedback',
    'CustomerFeedback'[Satisfaction_Score],
    'CustomerFeedback'[Satisfaction_Factor],
    "FactorCount", COUNTROWS('CustomerFeedback')
)

 2. Create one new column 'MaxCountPerScore' in this table. This is to give you maximum FactorCount within that Satisfaction_Score.

MaxCountPerScore = 
CALCULATE(
    MAX(FactorCountSummary[FactorCount]),
    ALLEXCEPT(FactorCountSummary, FactorCountSummary[Satisfaction_Score])
)

 3. Create another new 'Flag' Column used as filter/slicer for your visual. and the table will look like this,

ShowOnlyTopFactors = 
IF(
    FactorCountSummary[FactorCount] = FactorCountSummary[MaxCountPerScore],
    1,
    0
)

MasonMA_1-1751816822620.png

 

4. Set up the Culumn bar chart as below

MasonMA_0-1751816724887.png

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file. In the question, I saw the request about satisfaction factor and score, so I only created dimension tables for factor and score.

 

Jihwan_Kim_1-1751804486218.png

 

 

Jihwan_Kim_0-1751804475253.png

 

INDEX function (DAX) - DAX | Microsoft Learn

 

count: = 
COUNTROWS(customer_fact)

 

MAX count: = 
VAR _t =
    SUMMARIZE (
        ALL ( customer_fact ),
        Satisfaction_Score[Satisfaction_Score],
        Satisfaction_Factor[Satisfaction_Factor]
    )
VAR _max =
    INDEX (
        1,
        _t,
        ORDERBY ( [count:], DESC ),
        ,
        PARTITIONBY ( Satisfaction_Score[Satisfaction_Score] )
    )
VAR _maxcountfactorlist =
    SUMMARIZE ( _max, Satisfaction_Factor[Satisfaction_Factor] )
VAR _maxcount =
    CALCULATE (
        [count:],
        Satisfaction_Factor[Satisfaction_Factor] IN _maxcountfactorlist
    )
RETURN
    IF ( [count:] = _maxcount, [count:] )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
FBergamaschi
Resolver IV
Resolver IV

Not sure this could be OK, using tooltips to see the list of the top count factors, in a bar chart

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

 

image 2.png

FBergamaschi
Resolver IV
Resolver IV

Hi, here the DAX code in a table

 

I imported your table and named it "Tabella"

 

Then created the following measures

 

Count = COUNTROWS( Tabella )
 
Max Count for Factors =
MAXX (
    ADDCOLUMNS(
        VALUES( Tabella[Satisfaction_Factor] ),
        "@Count", [Count]
    ),
    [@Count]
)
 
Max Count Factors =
VAR FactorsAndCount =
 ADDCOLUMNS(
    VALUES( Tabella[Satisfaction_Factor] ),
    "@Count", [Count]
)
VAR MAXVALUE =
MAXX (
FactorsAndCount,[@Count]
)
RETURN
CONCATENATEX(
    FILTER (
        FactorsAndCount,
        [@Count] = MAXVALUE
    ),
    Tabella[Satisfaction_Factor], " / "
)
 
Result
 
image.png
I am not sure to to show something like this in a bar chart as the list of max count factors are texts, maybe you want to draw something to let me understand better ?
 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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