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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
dvavrous
Frequent Visitor

Count values that equal to Maximum per category.

Hello, 

hope I can get some help. 

I need to count only the values that are equal to maximum value per that category_2. It has to be measure as I want to use multiple slicers. Each time I filter the data by slicer the maximum changes.

Idcategory_1category_2evaluationslicer

1BikesCity Bike0Idea
2BikesCity Bike1Impl
3BikesCity Bike2Impl
4BikesCity Bike2Impl
5BikesCity Bike2Impl
6BikesMountain Bike0Idea
7BikesMountain Bike0Idea
8BikesOther0Idea


I feel I might be close with this measure but it is not quite right. 

count_max =
COUNTX (
    FILTER (
        'Table',
        CALCULATE (
            MAXX (
                SUMMARIZE (
                    ALLSELECTED ( 'Table' ),
                    'Table'[category_1],
                    'Table'[category_2],
                    "max_evaluation", CALCULATE ( MAX ( 'Table'[evaluation] ) )
                ),
                [max_evaluation]
            ),
            ALLEXCEPT ( 'Table', 'Table'[category_2], 'Table'[slicer] )
        ) = 'Table'[evaluation]
    ),
    COUNT ( 'Table'[category_2] )
)

 

It gets me to this: 
- the issue is with the total for category_1 (Bikes) that does not equal the maximum value for all.
Evaluation02
Bikes(blank)3
  City Bike 3
  Mountain2 
  Other1 
 

Expcted Result

Evaluation02
Bikes33
  City Bike 3
  Mountain 2 
  Other1 



Sample file

https://drive.google.com/file/d/1xZ7gv80k_l90SI6-RNRn83UTA8fhcPir/view?usp=sharinghttps://drive.goog...

Any help will be appreciated

1 ACCEPTED SOLUTION

Hello Jianpeng Li, thank you very much for your help.

It worked on the data I sent but it did not work on my original data. 
I must have made a mistake in my original measure that I shared.

Anyway I was able to come up with a different approach that worked.

For anyone interested see measure below.

MEASURE =
VAR _max_table =
SUMMARIZE (
ALLSELECTED ( 'Table 2' ),
'Table 2'[category_1],
'Table 2'[category_2],
"max_evaluation", CALCULATE ( MAX ( 'Table 2'[evaluation] ) )
)
VAR _values =
SELECTCOLUMNS (
'Table 2',
"category_1", 'Table 2'[category_1],
"category_2", 'Table 2'[category_2],
"evaluation", 'Table 2'[evaluation]
)
VAR _inter =
INTERSECT ( _max_table, _values )
RETURN
COUNTROWS ( _inter )


View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi, @dvavrous 

Based on the PBIX file you provided, I created a new measure using the following DAX expression:

MEASURE =
VAR _seleted =
    CALCULATE (
        SELECTEDVALUE ( 'Table'[evaluation] ),
        FILTER (
            'Table',
            CALCULATE (
                MAXX (
                    SUMMARIZE (
                        ALLSELECTED ( 'Table' ),
                        'Table'[category_1],
                        'Table'[category_2],
                        "max_evaluation", CALCULATE ( MAX ( 'Table'[evaluation] ) )
                    ),
                    [max_evaluation]
                ),
                ALLEXCEPT ( 'Table', 'Table'[category_2], 'Table'[slicer] )
            ) = 'Table'[evaluation]
        )
    )
RETURN
    IF (
        NOT ISINSCOPE ( 'Table'[category_2] ),
        SUMX ( FILTER ( 'Table', 'Table'[evaluation] = _seleted ), [count_max] ),
        COUNTX (
            FILTER (
                'Table',
                CALCULATE (
                    MAXX (
                        SUMMARIZE (
                            ALLSELECTED ( 'Table' ),
                            'Table'[category_1],
                            'Table'[category_2],
                            "max_evaluation", CALCULATE ( MAX ( 'Table'[evaluation] ) )
                        ),
                        [max_evaluation]
                    ),
                    ALLEXCEPT ( 'Table', 'Table'[category_2], 'Table'[slicer] )
                ) = 'Table'[evaluation]
            ),
            COUNT ( 'Table'[category_2] )
        )
    )

Here are the results:

vjianpengmsft_0-1714705328737.png

 

I've uploaded the PBIX file I used this time below.

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello Jianpeng Li, thank you very much for your help.

It worked on the data I sent but it did not work on my original data. 
I must have made a mistake in my original measure that I shared.

Anyway I was able to come up with a different approach that worked.

For anyone interested see measure below.

MEASURE =
VAR _max_table =
SUMMARIZE (
ALLSELECTED ( 'Table 2' ),
'Table 2'[category_1],
'Table 2'[category_2],
"max_evaluation", CALCULATE ( MAX ( 'Table 2'[evaluation] ) )
)
VAR _values =
SELECTCOLUMNS (
'Table 2',
"category_1", 'Table 2'[category_1],
"category_2", 'Table 2'[category_2],
"evaluation", 'Table 2'[evaluation]
)
VAR _inter =
INTERSECT ( _max_table, _values )
RETURN
COUNTROWS ( _inter )


Anonymous
Not applicable

Hi, @dvavrous 
Thank you very much for your reply. Did the DAX expression you shared solve your current problem?

 

Best Regards

Jianpeng Li

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors