问题
My current table looks like this
Company-----year----size-----Exchange
A-----------2000-----80-------A
A-----------2001-----85-------A
B-----------2002------90------C
I want to allocate the companies into two categories "Big" and "Small".
For a particular year, if the companies size is bigger than the median of the size of the companies in that year in Exchange A, will be called "BIG". something like this,
=if([size]>MEDIANX(filter(filter(tbl1,[Year]=A),[Year]),[size]),"Big","Small")
I know the way I used the filters are wrong. I do not know how to do this. Please help me.
回答1:
Your question isn't particularly well worded as it's left me wondering if I've made correct assumptions when answering but essentially I think you need something like an array formula with Median.
=IF(C2>MEDIAN(IF($D$2:$D$5="A",IF($B$2:$B$5=B2,$C$2:$C$5))),"Big","Small")
This should give you "Big" if for that year the companies size is bigger than the median of the size of the companies in that year in Exchange A.
回答2:
I assume you ask for a PowerPivot solution, since your question is tagged as such.
The DAX (a.k.a. Power Pivot) formula MEDIAN()
is only available in the preview edition of Excel 2016 (see here: https://msdn.microsoft.com/en-us/library/dn802551.aspx).
However, you can simply build your own median logic using RANKX()
First, add a new column called [RankInExchangeA]
:
=If([Exchange]="A",RANKX(FILTER(Table1,[Exchange]="A" && EARLIER([year])=[year]),[size]),Blank())
The EARLIER()
function basically means ThisRowsValue()
.
Now add your desired Big/Small column:
=If([Exchange]="A",If([RankInExchangeA]<=CALCULATE(max([RankInExchangeA]),filter(Table1,EARLIER([year])=[year]))/2,"Small","Big"),"Other Exchange")
EDIT: Added the year condition to the formulas.
EDIT 2: As mentioned in the comments, the following formula would work using MEDIANX()
:
=IF([size]>MEDIANX(FILTER(Table,[Exchange]="A"&&EARLIER([date])=[date]),[size]),"Big","Small")
来源:https://stackoverflow.com/questions/38246651/sorting-portfolios-based-on-criterias