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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Speedbird
Frequent Visitor

Count frequency of measure with respect to column

I have data where i, y and value are columns, and I've made measures max_val to find maximum of value across y for each i and y_max_val to identify the y where the maximum value occurred.

iyvalue[max_val][y_max_val]
120200.960.962020
120250.60.962020
120300.060.962020
220200.770.792030
220250.30.792030
220300.790.792030
320200.630.632020
320250.020.632020
320300.170.632020
420200.930.932020
420250.520.932020
420300.860.932020
520200.90.92020
520250.550.92020
520300.440.92020

 

How do I write a measure to count the number of times y has the maximum value?

I'd like something like:

20204
20250
20301
1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Speedbird ,

 

Create a measure like so:

count =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[i] ) + 0,
    FILTER ( 'Table', 'Table'[y] = [y_max_val] )
)

count.PNG

 

BTW, .pbix file attached.

 

 

Best Regards,

Icey

 

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

View solution in original post

6 REPLIES 6
Icey
Community Support
Community Support

Hi @Speedbird ,

 

Create a measure like so:

count =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[i] ) + 0,
    FILTER ( 'Table', 'Table'[y] = [y_max_val] )
)

count.PNG

 

BTW, .pbix file attached.

 

 

Best Regards,

Icey

 

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

harshnathani
Community Champion
Community Champion

HI @Speedbird ,

 

 

You will need to create a Calculated Column

 

Value equal Max Val =
IF (
    'Table'[value] = 'Table'[max_val],
    1,
    0
)

 

1.jpg

 

 

 

Then create a measure

 

Count of y and max_Val =
COALESCE (
    CALCULATE (
        COUNT ( 'Table'[i] ),
        'Table'[Value equal Max Val] = 1
    ),
    0
)

 

 

2.JPG

 


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression to get your desired result.

 

Count of Max =
VAR __summary =
    ADDCOLUMNS (
        SUMMARIZE ( iyTable, iyTable[y], iyTable[i] ),
        "ivalue", CALCULATE ( MAX ( iyTable[value] ) ),
        "imax", CALCULATE ( MAX ( iyTable[value] ), ALL ( iyTable[y] ) )
    )
RETURN
    COUNTROWS ( FILTER ( __summary, [ivalue] = [imax] ) ) + 0

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi Pat,

 

Thanks for your answer! Unfortunately, it hasn't worked for me. The result I get from this measure is essentially the count of i for all years:

yCount of Max
20205
20255
2030

5

 

Sorry, there is a bit more context, the table I showed in the OP is a filtered version of the full table, there are other ids in that table and also other years that page level slicers select for me.

Since there are other columns in play, please see if this variation does the trick

 

Count of Max =
VAR __summary =
    ADDCOLUMNS (
        SUMMARIZE ( iyTable, iyTable[y], iyTable[i] ),
        "ivalue", CALCULATE ( MAX ( iyTable[value] ) ),
        "imax", CALCULATE ( MAX ( iyTable[value] ), ALLEXCEPT ( iytable, iyTable[i] ) )
    )
RETURN
    COUNTROWS ( FILTER ( __summary, [ivalue] = [imax] ) ) + 0

 

You could also try ALLSELECTED(iyTable) in place of the original ALL() as well.

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks Pat, but ALLEXCEPT gives me count of i for all years, and ALLSELECTED gives me 1.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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