— CAN YOU SOLVE THIS - EXCEL CHALLENGE 189 —
(Solutions in any language are also welcome for Excel Challenges)
Populate the count of numbers larger than the number given in a cell. The range to be considered is not entire column but starting that cell till the end. Hence, in case of A4, the you need to find the count of numbers > A4 in the range A4:A20
Post answers in Comment.
(Your formula need not be a single formula. You can write multiple formulas to arrive at a solution. Also your formula need not be different from others as long as you have worked out your formula independently)
Download Practice File - https://lnkd.in/daFTUKga
#excel, #excelchallenge, #powerquerychallenge, #daxchallenge, #m, #dax, #powerbi, #powerquery, #powerpivot, #sheets, #googlesheets, #data, #analytics, #businessintelligence, #finance, #office365, #python, #r
Excel BI’s LinkedIn post:
Counting of elements w/ #powerquery. #bitanbit #powerbi
let
Source = Excel.CurrentWorkbook(){[Name="Input"]}[Content],
Solution =
let
Numbers = List.Accumulate(Source[Numbers], {}, (s, c) => s & {{(List.Last(s){0}? ?? -1) + 1, c}})
in
List.Transform(Numbers, (l) => List.Count([List.Select](http://list.select/)(List.Skip(Numbers, l{0}), each _{1} > l{1})))
in
Solution
Adjunto mi query…
No me dan los mismos resultados que en la imagen. Sin embargo, el resultado es igual al de Bo Rydobon y, por supuesto, con una query no tan sofisticada como la de Bo.
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Index = Table.AddIndexColumn(Source, "Idx"),
Sol = Table.AddColumn(Index, "Answer", (x)=>
let
a = Source[Numbers],
b = List.LastN(a, List.Max(a) - Index[Idx]{x[Idx]}),
c = [List.Select](http://list.select/)(b, each _ > Index[Numbers]{x[Idx]})
in List.Count(c))[[Answer]]
in
Sol
=LET(
_num, A2:A20,
_seq, SEQUENCE(ROWS(_num)),
MAP(_seq, LAMBDA(a, SUM(N(DROP(_num, a - 1) > CHOOSEROWS(_num, a)))))
)
with the same mismatches of others
Mind blower solution : (pick only restrictive array and compare)
=MAP(A2:A20,SEQUENCE(ROWS(A2:A20)),LAMBDA(a,b,REDUCE(0,DROP(A2:A20,b-1),LAMBDA(ac,v,IF(v>a,ac+1,ac)))))
But, a simple =COUNTIFS(A2:$A$20,“>”&A2) then pasted down works.
I suppose I can use my brain a bit and come up with a single formula using MAP, REDUCE, and what have you. But you know what, it can be done with a simple COUNTIF, so that’s what I’m going with since my brain is not big enough😅
To be placed in B2 and then copy/pasted down.
Hi to all!
Two options:
=MAP(A2:A20,LAMBDA(x,COUNTIF(x:A20,">"&x)))
=MAP(A2:A20,LAMBDA(x,SUM(N(x:A20>x))))
Blessings!
=MAP(A2:A20,LAMBDA(a,SUM(0+(a:A20>a))))
EDIT NOTE: I get the same mismatches as Bo Rydobon did.
I got mismatch on B2 18>17 , B9 12>11 and B18 3>2
Not sure how to count that
=MAP(A2:A20,LAMBDA(a,COUNTIF(a:A20,">"&a)))
hi everyone, my proposal solution:
=MAP(A2:A20, LAMBDA(a, COUNTIF(DROP(A2:A20, ROWS(A2:a)-1), ">"&a)))
Quick and easy, but longer than others