How COUNT number MAX Values in column?

citizenbh

Board Regular
Joined
Sep 19, 2013
Messages
145
Sample:
I have count number max values by Type

Table:
NameTypeValue
a1100
b167
c1100
d188
e135
f2200
g2123
h2178
i2200
j2200
k3198
l3300
m3256
n3248
o3180

<tbody>
</tbody>
________________________
Result:
TypeCount(Max)
12
23
31

<tbody>
</tbody>
---------------------------
Thx
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Code:
Table[CountMax]
:=CALCULATE(
    COUNTROWS(Table),
    FILTER(
        Table,
        Table[Value] = MAX(Table[Value])
    )
)
 
Upvote 0
An alternative using LASTNONBLANK:
Code:
=CALCULATE(
    COUNTROWS(Table),
    LASTNONBLANK( Table[Value], 0)
)
 
Upvote 0
Could you explain how that use of LASTNONBLANK works? I'm having trouble wrapping my head around it. Does LASTNONBLANK treat the given column as being in ascending numeric order automatically? I don't see anything about that in the documentation but otherwise I don't get how it would give you the max. I also don't get the use of 0 as the expression. But this looks like a pretty cool trick if I could see what makes it work.
 
Upvote 0
Sure,
  • LASTNONBLANK will return the "last" value of the single-column table (or column) provided in the first argument, restricted to values where the second argument is nonblank.
  • Last = max for numbers, or lexicographically last for strings etc, while MAX only works with numbers.
  • The other difference to MAX is that LASTNONBLANK actually returns a single-row, single-column table containing the "last" value (This will be treated as a scalar or table depending on context).
    This allows LASTNONBLANK to be used as a filter argument in CALCULATE, for example.
  • By using an arbitrary nonblank second argument like I did (e.g. 0 or 1), LASTNONBLANK is just like MAX but returns a table rather than a scalar.

SQLBI has a good page on FIRST/LASTNONBLANK:
https://www.sqlbi.com/articles/alternative-use-of-firstnonblank-and-lastnonblank/
 
Upvote 0
Thanks guys!

I've got such a table

TypeValueSum of Table[CountMax]
11002
881
671
351
22003
1781
1231
33001
2561
2481
1981
1801
Grand Total15

<tbody>
</tbody>

Is it possible to get a summary table above in the first post
 
Upvote 0
Count the number different Values per group Type
=CALCULATE(DISTINCTCOUNT([Value]);FILTER(Table1;[Type]=EARLIER(Table1[Type])))

Account MAX Value per group Type
=CALCULATE(MAX([Value]);FILTER(Table1;[Type]=EARLIER(Table1[Type])))

When we put them in an area ΣValues all give the same result (ValueField Settings: Count) as previus posts,
but I can't get a summary table of the first post.
 
Upvote 0
You can get the summary table from the first post by using one of the Countmax measures (from posts 2-3) as long as you have Type but not Value as row fields.
Is that what you were getting at?
 
Upvote 0
Exactly. Sorry, my mistake, the table should look like this:

Result:

TypeMAXVALCount(Max)
11002
22003
33001

<tbody>
</tbody>
---------------------------
 
Upvote 0
Ok, I solved

TypeMAXVALTable[CountMax]
11002
22003
33001

<tbody>
</tbody>

Rows:Type, MAXVAL
ΣValues:Table[CountMax] - no calculation
DAX Column:MAXVAL=CALCULATE(MAX([Value]);FILTER('Table';[Type]=EARLIER('Table'[Type])))
Table[CountMax]- from post 2

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,175
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top