How can I calculate the TRIMMEAN in SQL Server?
Executing the TRIMMEAN in Excel for the example data below and percent of 0.35 my result is: 0.10
I've tried so many ways but not success.
example data
CREATE TABLE [dbo].[YourTable](
[Data] [decimal](18, 8) NOT NULL
);
WITH Nums AS
(
SELECT number
FROM master..spt_values
WHERE type='P' AND number > 0
), Vals As
(
SELECT *
FROM (VALUES
(2,0.03555556),
(1,0.05777778),
(1,0.05888889),
(1,0.05916667),
(2,0.05944444),
(2,0.06000000),
(3,0.06027778),
(1,0.06055556),
(2,0.06083333),
(2,0.06111111),
(2,0.06138889),
(2,0.06166667),
(2,0.06194444),
(2,0.06222222),
(3,0.06250000),
(1,0.06277778),
(2,0.06305556),
(3,0.06361111),
(7,0.06388889),
(4,0.06416667),
(3,0.06444444),
(8,0.06472222),
(4,0.06500000),
(5,0.06527778),
(3,0.06555556),
(9,0.06583333),
(8,0.06611111),
(8,0.06638889),
(5,0.06666667),
(10,0.06694444),
(6,0.06722222),
(16,0.06750000),
(13,0.06777778),
(10,0.06805556),
(4,0.06833333),
(7,0.06861111),
(10,0.06888889),
(8,0.06916667),
(10,0.06944444),
(14,0.06972222),
(14,0.07000000),
(15,0.07027778),
(15,0.07055556),
(21,0.07083333),
(19,0.07111111),
(20,0.07138889),
(20,0.07166667),
(18,0.07194444),
(24,0.07222222),
(19,0.07250000),
(17,0.07277778),
(15,0.07305556),
(23,0.07333333),
(25,0.07361111),
(26,0.07388889),
(22,0.07416667),
(22,0.07444444),
(24,0.07472222),
(19,0.07500000),
(20,0.07527778),
(29,0.07555556),
(33,0.07583333),
(16,0.07611111),
(30,0.07638889),
(20,0.07666667),
(25,0.07694444),
(37,0.07722222),
(32,0.07750000),
(25,0.07777778),
(25,0.07805556),
(34,0.07833333),
(28,0.07861111),
(22,0.07888889),
(25,0.07916667),
(27,0.07944444),
(24,0.07972222),
(28,0.08000000),
(31,0.08027778),
(34,0.08055556),
(21,0.08083333),
(23,0.08111111),
(23,0.08138889),
(18,0.08166667),
(22,0.08194444),
(18,0.08222222),
(30,0.08250000),
(26,0.08277778),
(31,0.08305556),
(24,0.08333333),
(20,0.08361111),
(21,0.08388889),
(26,0.08416667),
(29,0.08444444),
(39,0.08472222),
(20,0.08500000),
(25,0.08527778),
(28,0.08555556),
(31,0.08583333),
(29,0.08611111),
(21,0.08638889),
(16,0.08666667),
(27,0.08694444),
(21,0.08722222),
(16,0.08750000),
(23,0.08777778),
(21,0.08805556),
(24,0.08833333),
(24,0.08861111),
(21,0.08888889),
(23,0.08916667),
(23,0.08944444),
(15,0.08972222),
(21,0.09000000),
(18,0.09027778),
(19,0.09055556),
(15,0.09083333),
(19,0.09111111),
(17,0.09138889),
(18,0.09166667),
(21,0.09194444),
(14,0.09222222),
(19,0.09250000),
(21,0.09277778),
(25,0.09305556),
(18,0.09333333),
(17,0.09361111),
(20,0.09388889),
(25,0.09416667),
(18,0.09444444),
(16,0.09472222),
(21,0.09500000),
(9,0.09527778),
(16,0.09555556),
(16,0.09583333),
(16,0.09611111),
(14,0.09638889),
(15,0.09666667),
(18,0.09694444),
(15,0.09722222),
(13,0.09750000),
(20,0.09777778),
(18,0.09805556),
(19,0.09833333),
(24,0.09861111),
(17,0.09888889),
(10,0.09916667),
(10,0.09944444),
(17,0.09972222),
(16,0.10000000),
(17,0.10027778),
(15,0.10055556),
(10,0.10083333),
(17,0.10111111),
(19,0.10138889),
(14,0.10166667),
(9,0.10194444),
(15,0.10222222),
(14,0.10250000),
(15,0.10277778),
(14,0.10305556),
(7,0.10333333),
(13,0.10361111),
(19,0.10388889),
(10,0.10416667),
(9,0.10444444),
(9,0.10472222),
(16,0.10500000),
(16,0.10527778),
(8,0.10555556),
(10,0.10583333),
(15,0.10611111),
(12,0.10638889),
(10,0.10666667),
(9,0.10694444),
(12,0.10722222),
(9,0.10750000),
(17,0.10777778),
(8,0.10805556),
(14,0.10833333),
(9,0.10861111),
(9,0.10888889),
(8,0.10916667),
(13,0.10944444),
(16,0.10972222),
(10,0.11000000),
(12,0.11027778),
(10,0.11055556),
(11,0.11083333),
(9,0.11111111),
(12,0.11138889),
(10,0.11166667),
(8,0.11194444),
(15,0.11222222),
(7,0.11250000),
(9,0.11277778),
(10,0.11305556),
(7,0.11333333),
(12,0.11361111),
(8,0.11388889),
(5,0.11416667),
(13,0.11444444),
(8,0.11472222),
(9,0.11500000),
(5,0.11527778),
(6,0.11555556),
(6,0.11583333),
(9,0.11611111),
(12,0.11638889),
(4,0.11666667),
(8,0.11694444),
(7,0.11722222),
(12,0.11750000),
(9,0.11777778),
(8,0.11805556),
(8,0.11833333),
(5,0.11861111),
(7,0.11888889),
(4,0.11916667),
(5,0.11944444),
(5,0.11972222),
(11,0.12000000),
(1,0.12027778),
(8,0.12055556),
(7,0.12083333),
(8,0.12111111),
(9,0.12138889),
(7,0.12166667),
(3,0.12194444),
(11,0.12222222),
(9,0.12250000),
(8,0.12277778),
(9,0.12305556),
(4,0.12333333),
(5,0.12361111),
(3,0.12388889),
(3,0.12416667),
(13,0.12444444),
(7,0.12472222),
(8,0.12500000),
(8,0.12527778),
(5,0.12555556),
(6,0.12583333),
(6,0.12611111),
(3,0.12638889),
(6,0.12666667),
(5,0.12694444),
(9,0.12722222),
(4,0.12750000),
(6,0.12777778),
(7,0.12805556),
(8,0.12833333),
(7,0.12861111),
(8,0.12888889),
(9,0.12916667),
(8,0.12944444),
(4,0.12972222),
(2,0.13000000),
(5,0.13027778),
(3,0.13055556),
(8,0.13083333),
(4,0.13111111),
(1,0.13138889),
(3,0.13166667),
(9,0.13194444),
(12,0.13222222),
(8,0.13250000),
(4,0.13277778),
(5,0.13305556),
(4,0.13333333),
(11,0.13361111),
(7,0.13388889),
(8,0.13416667),
(2,0.13444444),
(10,0.13472222),
(5,0.13500000),
(5,0.13527778),
(5,0.13583333),
(10,0.13611111),
(2,0.13638889),
(8,0.13666667),
(3,0.13694444),
(8,0.13722222),
(5,0.13750000),
(4,0.13777778),
(5,0.13805556),
(8,0.13833333),
(2,0.13861111),
(2,0.13888889),
(7,0.13916667),
(5,0.13972222),
(10,0.14000000),
(4,0.14027778),
(4,0.14055556),
(6,0.14083333),
(5,0.14111111),
(3,0.14138889),
(5,0.14166667),
(4,0.14194444),
(7,0.14222222),
(5,0.14250000),
(6,0.14277778),
(5,0.14305556),
(7,0.14333333),
(6,0.14361111),
(9,0.14388889),
(7,0.14416667),
(3,0.14444444),
(4,0.14472222),
(5,0.14500000),
(4,0.14527778),
(7,0.14555556),
(5,0.14583333),
(4,0.14611111),
(5,0.14638889),
(4,0.14666667),
(2,0.14694444),
(8,0.14722222),
(5,0.14750000),
(3,0.14777778),
(5,0.14805556),
(6,0.14833333),
(3,0.14861111),
(3,0.14888889),
(8,0.14916667),
(4,0.14944444),
(6,0.14972222),
(5,0.15000000),
(4,0.15027778),
(3,0.15055556),
(1,0.15083333),
(1,0.15111111),
(3,0.15138889),
(6,0.15166667),
(2,0.15194444),
(3,0.15222222),
(2,0.15250000),
(2,0.15277778),
(1,0.15305556),
(2,0.15333333),
(2,0.15361111),
(2,0.15388889),
(1,0.15416667),
(8,0.15444444),
(5,0.15472222),
(2,0.15500000),
(1,0.15527778),
(4,0.15555556),
(2,0.15583333),
(3,0.15611111),
(1,0.15666667),
(1,0.15722222),
(2,0.15750000),
(3,0.15777778),
(2,0.15805556),
(3,0.15833333),
(2,0.15861111),
(4,0.15888889),
(3,0.15916667),
(2,0.15944444),
(3,0.15972222),
(4,0.16000000),
(1,0.16055556),
(2,0.16083333),
(4,0.16111111),
(4,0.16138889),
(4,0.16166667),
(2,0.16194444),
(5,0.16222222),
(1,0.16250000),
(3,0.16333333),
(1,0.16388889),
(2,0.16416667),
(1,0.16444444),
(1,0.16472222),
(1,0.16500000),
(2,0.16527778),
(1,0.16555556),
(1,0.16611111),
(1,0.16638889),
(4,0.16666667),
(3,0.16694444),
(3,0.16722222),
(1,0.16750000),
(1,0.16777778),
(2,0.16833333),
(4,0.16861111),
(2,0.16888889),
(1,0.16916667),
(1,0.16972222),
(2,0.17000000),
(2,0.17027778),
(3,0.17055556),
(2,0.17083333),
(2,0.17111111),
(3,0.17138889),
(2,0.17166667),
(1,0.17194444),
(2,0.17222222),
(2,0.17250000),
(5,0.17277778),
(5,0.17305556),
(3,0.17333333),
(2,0.17361111),
(3,0.17388889),
(3,0.17416667),
(2,0.17444444),
(2,0.17472222),
(1,0.17527778),
(3,0.17555556),
(1,0.17583333),
(2,0.17611111),
(1,0.17666667),
(3,0.17722222),
(3,0.17750000),
(1,0.17777778),
(1,0.17805556),
(3,0.17833333),
(5,0.17861111),
(4,0.17888889),
(2,0.17916667),
(1,0.17944444),
(2,0.18000000),
(1,0.18027778),
(2,0.18055556),
(2,0.18083333),
(1,0.18111111),
(2,0.18138889),
(4,0.18166667),
(2,0.18194444),
(1,0.18222222),
(1,0.18250000),
(1,0.18277778),
(2,0.18361111),
(1,0.18388889),
(1,0.18416667),
(3,0.18444444),
(2,0.18472222),
(4,0.18500000),
(2,0.18527778),
(2,0.18583333),
(3,0.18611111),
(1,0.18638889),
(1,0.18666667),
(1,0.18694444),
(2,0.18722222),
(1,0.18861111),
(4,0.18888889),
(1,0.18916667),
(1,0.18944444),
(1,0.18972222),
(2,0.19000000),
(1,0.19027778),
(1,0.19083333),
(1,0.19111111),
(1,0.19194444),
(2,0.19222222),
(1,0.19250000),
(1,0.19361111),
(1,0.19388889),
(1,0.19416667),
(1,0.19444444),
(1,0.19472222),
(1,0.19500000),
(1,0.19555556),
(3,0.19583333),
(2,0.19638889),
(3,0.19666667),
(2,0.19722222),
(1,0.19777778),
(2,0.19805556),
(1,0.19833333),
(2,0.19861111),
(2,0.19888889),
(1,0.19916667),
(1,0.19944444),
(2,0.20027778),
(1,0.20055556),
(2,0.20083333),
(2,0.20138889),
(1,0.20194444),
(2,0.20222222),
(1,0.20250000),
(1,0.20277778),
(1,0.20333333),
(1,0.20361111),
(1,0.20388889),
(1,0.20444444),
(1,0.20500000),
(2,0.20527778),
(3,0.20555556),
(1,0.20583333),
(1,0.20611111),
(3,0.20638889),
(2,0.20666667),
(2,0.20694444),
(1,0.20750000),
(1,0.20805556),
(3,0.20833333),
(1,0.20888889),
(1,0.20916667),
(1,0.20944444),
(2,0.20972222),
(1,0.21000000),
(1,0.21027778),
(1,0.21055556),
(2,0.21083333),
(1,0.21111111),
(2,0.21138889),
(2,0.21166667),
(1,0.21194444),
(3,0.21250000),
(2,0.21277778),
(1,0.21305556),
(2,0.21333333),
(2,0.21361111),
(2,0.21388889),
(2,0.21416667),
(1,0.21472222),
(1,0.21500000),
(1,0.21694444),
(1,0.21750000),
(4,0.21777778),
(2,0.21861111),
(1,0.21888889),
(3,0.21916667),
(1,0.21944444),
(2,0.21972222),
(1,0.22000000),
(1,0.22027778),
(1,0.22055556),
(1,0.22083333),
(1,0.22111111),
(1,0.22138889),
(1,0.22166667),
(1,0.22194444),
(3,0.22222222),
(1,0.22277778),
(3,0.22333333),
(1,0.22416667),
(1,0.22555556),
(2,0.22583333),
(1,0.22666667),
(1,0.22722222),
(1,0.22750000),
(5,0.22777778),
(1,0.22805556),
(2,0.22833333),
(3,0.22916667),
(1,0.22944444),
(1,0.22972222),
(1,0.23000000),
(2,0.23027778),
(1,0.23083333),
(1,0.23166667),
(1,0.23444444),
(1,0.23500000),
(1,0.23583333),
(1,0.23638889),
(2,0.23694444),
(1,0.23722222),
(1,0.23750000),
(1,0.23805556),
(1,0.23861111),
(2,0.23888889),
(1,0.23916667),
(1,0.23944444),
(1,0.23972222),
(2,0.24000000),
(2,0.24055556),
(3,0.24083333),
(1,0.24166667),
(1,0.24194444),
(1,0.24250000),
(2,0.24388889),
(1,0.24416667),
(1,0.24555556),
(1,0.24583333),
(4,0.24611111),
(2,0.24777778),
(1,0.24833333),
(1,0.24916667),
(1,0.24972222),
(1,0.25000000),
(1,0.25083333),
(1,0.25138889),
(1,0.25166667),
(2,0.25222222),
(3,0.25250000),
(1,0.25305556),
(2,0.25361111),
(2,0.25416667),
(1,0.25444444),
(2,0.25555556),
(2,0.25638889),
(1,0.25666667),
(1,0.25777778),
(1,0.25805556),
(1,0.25833333),
(2,0.25861111),
(1,0.25916667),
(1,0.25944444),
(1,0.26000000),
(2,0.26111111),
(1,0.26138889),
(2,0.26194444),
(3,0.26222222),
(2,0.26277778),
(2,0.26388889),
(1,0.26416667),
(1,0.26444444),
(1,0.26472222),
(1,0.26583333),
(1,0.26611111),
(4,0.26638889),
(1,0.26694444),
(1,0.26750000),
(1,0.26777778),
(1,0.26861111),
(1,0.26888889),
(1,0.26944444),
(1,0.26972222),
(1,0.27027778),
(1,0.27083333),
(1,0.27111111),
(1,0.27166667),
(1,0.27361111),
(1,0.27527778),
(1,0.27666667),
(1,0.27694444),
(2,0.27722222),
(1,0.27750000),
(1,0.27805556),
(1,0.27833333),
(1,0.28000000),
(2,0.28027778),
(1,0.28055556),
(2,0.28083333),
(1,0.28166667),
(1,0.28194444),
(1,0.28277778),
(1,0.28305556),
(1,0.28388889),
(1,0.28555556),
(1,0.28611111),
(1,0.28638889),
(1,0.28694444),
(1,0.28750000),
(1,0.28777778),
(1,0.28805556),
(1,0.28861111),
(1,0.28888889),
(1,0.28944444),
(1,0.29083333),
(1,0.29111111),
(1,0.29222222),
(1,0.29250000),
(1,0.29277778),
(1,0.29388889),
(1,0.29416667),
(1,0.29444444),
(1,0.29472222),
(1,0.29500000),
(2,0.29583333),
(2,0.29611111),
(2,0.29638889),
(1,0.29666667),
(1,0.29694444),
(1,0.29750000),
(1,0.29805556),
(1,0.30000000),
(1,0.30027778),
(1,0.30055556),
(2,0.30111111),
(2,0.30166667),
(1,0.30222222),
(1,0.30250000),
(2,0.30277778),
(1,0.30361111),
(2,0.30444444),
(2,0.30500000),
(1,0.30555556),
(1,0.30583333),
(1,0.30638889),
(1,0.30694444),
(1,0.30722222),
(1,0.30777778),
(1,0.30888889),
(2,0.31000000),
(1,0.31027778),
(2,0.31055556),
(1,0.31138889),
(2,0.31222222),
(1,0.31250000),
(1,0.31388889),
(1,0.31416667),
(2,0.31527778),
(1,0.31583333),
(2,0.31638889),
(1,0.31722222),
(1,0.31777778),
(1,0.31861111),
(1,0.31888889),
(1,0.32027778),
(1,0.32083333),
(1,0.32111111),
(1,0.32222222),
(1,0.32277778),
(1,0.32388889),
(2,0.32416667),
(1,0.32444444),
(1,0.32527778),
(1,0.32583333),
(1,0.32638889),
(1,0.32694444),
(1,0.32805556),
(2,0.32833333),
(1,0.32888889),
(1,0.32972222),
(1,0.33055556),
(1,0.33111111),
(1,0.33166667),
(1,0.33333333),
(1,0.33527778),
(1,0.33611111),
(2,0.33638889),
(1,0.33666667),
(3,0.33833333),
(1,0.34000000),
(1,0.34027778),
(1,0.34166667),
(1,0.34333333),
(1,0.34388889),
(1,0.34416667),
(1,0.34444444),
(1,0.34472222),
(2,0.34555556),
(1,0.34638889),
(1,0.34666667),
(1,0.34750000),
(1,0.34777778),
(1,0.34805556),
(1,0.34833333),
(1,0.34972222),
(1,0.35055556),
(1,0.35083333),
(1,0.35111111),
(1,0.35194444),
(1,0.35277778),
(1,0.35361111),
(2,0.35444444),
(1,0.35583333),
(1,0.35777778),
(1,0.35833333),
(1,0.35916667),
(1,0.36111111),
(1,0.36222222),
(1,0.36305556),
(2,0.36555556),
(1,0.36694444),
(2,0.36722222),
(1,0.36777778),
(1,0.36944444),
(1,0.37027778),
(1,0.37111111),
(1,0.37194444),
(1,0.37416667),
(1,0.37666667),
(1,0.37750000),
(1,0.37805556),
(1,0.38222222),
(1,0.38416667),
(1,0.38555556),
(1,0.38666667),
(1,0.38805556),
(1,0.39166667),
(1,0.39194444),
(1,0.39416667),
(1,0.39666667),
(1,0.39694444),
(1,0.40055556),
(1,0.40166667),
(1,0.40388889),
(1,0.40416667),
(1,0.40444444),
(1,0.40750000),
(1,0.40805556),
(1,0.41250000),
(2,0.41361111),
(1,0.41722222),
(1,0.41916667),
(1,0.42027778),
(1,0.42194444),
(1,0.42361111),
(1,0.42388889),
(1,0.42972222),
(1,0.43222222),
(1,0.43277778),
(1,0.43750000),
(1,0.43777778),
(1,0.43833333),
(1,0.44611111),
(1,0.44638889),
(1,0.44694444),
(1,0.45027778),
(1,0.45166667),
(1,0.45500000),
(1,0.45833333),
(1,0.46083333),
(1,0.46555556),
(1,0.46722222),
(2,0.46888889),
(1,0.47083333),
(1,0.47111111),
(1,0.47416667),
(1,0.47500000),
(1,0.47694444),
(2,0.48000000),
(2,0.48027778),
(1,0.48083333),
(1,0.48111111),
(1,0.48500000),
(1,0.48611111),
(1,0.49444444),
(1,0.49555556),
(1,0.50000000),
(1,0.51000000),
(1,0.51472222),
(1,0.51916667),
(1,0.52638889),
(1,0.52833333),
(1,0.53861111),
(1,0.55055556),
(1,0.55722222),
(1,0.56111111),
(1,0.56750000),
(1,0.56833333),
(1,0.56944444),
(1,0.59500000),
(1,0.59861111),
(1,0.60472222),
(1,0.60750000),
(1,0.61000000),
(1,0.61027778),
(1,0.61138889),
(1,0.61888889),
(1,0.62472222),
(1,0.62916667),
(1,0.63000000),
(1,0.63055556),
(1,0.63138889),
(1,0.63527778),
(1,0.63666667),
(1,0.64277778),
(1,0.64666667),
(1,0.66333333),
(1,0.67277778),
(1,0.68500000),
(1,0.69083333),
(1,0.69916667),
(1,0.70166667),
(1,0.71833333),
(1,0.72527778),
(1,0.72638889),
(1,0.73861111),
(2,0.73944444),
(1,0.75944444),
(1,0.76166667),
(1,0.76194444),
(1,0.77500000),
(1,0.77888889),
(1,0.78888889),
(1,0.80083333),
(1,0.80416667),
(1,0.80611111),
(2,0.80638889),
(1,0.81027778),
(1,0.81277778),
(1,0.81722222),
(1,0.81833333),
(1,0.83138889),
(1,0.84555556),
(1,0.84833333),
(1,0.85138889),
(1,0.85277778),
(1,0.85472222),
(1,0.86444444),
(1,0.86527778),
(1,0.90027778),
(1,0.90500000),
(1,0.92305556),
(1,0.93361111),
(1,0.93527778),
(1,0.94861111),
(2,0.95055556),
(1,0.95222222),
(1,0.96000000),
(1,0.96472222),
(1,0.96527778),
(1,0.97472222),
(1,0.98166667),
(1,1.00555556),
(1,1.00666667),
(1,1.00777778),
(1,1.01250000),
(1,1.01638889),
(1,1.01861111),
(1,1.02111111),
(1,1.02305556),
(1,1.02500000),
(1,1.02666667),
(1,1.02694444),
(1,1.02805556),
(1,1.03000000),
(2,1.03638889),
(1,1.04111111),
(1,1.04222222),
(1,1.04527778),
(1,1.04583333),
(1,1.04750000),
(1,1.04805556),
(1,1.04944444),
(1,1.05138889),
(1,1.05583333),
(1,1.05638889),
(1,1.05944444),
(1,1.05972222),
(1,1.06138889),
(1,1.06250000),
(1,1.06305556),
(1,1.06500000),
(1,1.06666667),
(1,1.06750000),
(1,1.07083333),
(1,1.07277778),
(1,1.07388889),
(1,1.08361111),
(1,1.08666667),
(1,1.09055556),
(1,1.09222222),
(1,1.09805556),
(1,1.11527778),
(1,1.11805556),
(1,1.12777778),
(1,1.13222222),
(1,1.13250000),
(1,1.13361111),
(1,1.13388889),
(1,1.15027778),
(1,1.15194444),
(1,1.15444444),
(1,1.15916667),
(1,1.16111111),
(1,1.16666667),
(1,1.16750000),
(1,1.17222222),
(1,1.17694444),
(1,1.18166667),
(1,1.19305556),
(1,1.20138889),
(1,1.23777778),
(1,1.27861111),
(1,1.29916667),
(1,1.33638889),
(1,1.39750000),
(1,1.42250000),
(1,1.42611111),
(1,1.50111111),
(1,1.61583333),
(1,1.62166667),
(1,1.62500000),
(1,1.63361111),
(1,1.65916667),
(1,1.68666667),
(1,1.68722222),
(1,1.71638889),
(1,1.71861111),
(1,2.10222222),
(1,2.12611111),
(1,2.19416667),
(1,2.20055556),
(1,2.53527778),
(1,2.74638889),
(1,2.79361111),
(1,2.99055556),
(1,3.06277778),
(1,4.24166667),
(1,5.93750000),
(1,8.91694444),
(1,13.53277778),
(1,14.47305556),
(1,14.52361111),
(1,14.55805556),
(1,14.56611111),
(1,14.57138889),
(1,14.60777778),
(1,14.60972222),
(1,14.61722222),
(1,14.61888889),
(1,14.63277778),
(1,14.64305556),
(1,14.66527778),
(1,14.75722222),
(1,14.76000000),
(1,14.91777778),
(1,14.92305556),
(1,15.09722222),
(1,16.23472222),
(1,16.24388889),
(1,16.24722222),
(1,16.29055556),
(1,16.29333333),
(1,59.44916667),
(1,59.71000000),
(1,59.71583333),
(1,59.82138889),
(1,60.05555556),
(1,61.05055556),
(1,61.05694444),
(1,61.11000000),
(1,61.11222222),
(1,61.11527778),
(1,61.11555556),
(1,61.12750000),
(1,61.12972222),
(1,61.13000000),
(1,62.50416667),
(1,62.51166667),
(1,62.52833333),
(1,62.55138889),
(1,62.55750000),
(1,62.56861111),
(1,62.58777778),
(1,62.58833333),
(1,62.59472222),
(1,62.60194444),
(1,62.61416667),
(1,62.64250000),
(1,62.68222222),
(1,62.68805556),
(1,63.12638889),
(1,63.15666667),
(1,63.27472222)
) V(Count,Data))
INSERT INTO [dbo].[YourTable]
SELECT Data
FROM Vals
JOIN Nums ON number <= Count
This is a simplified version of #MartinSmith's answer which avoids calculating two ROW_NUMBERs with different order:
WITH T AS
(
SELECT [Data],
COUNT(*) OVER() AS cnt,
CAST(#Percent * COUNT(*) OVER() AS INT)/2 AS NumToExclude,
ROW_NUMBER() OVER (ORDER BY [Data] ASC) AS RN
FROM [dbo].[YourTable]
WHERE [Data] IS NOT NULL
)
SELECT AVG([Data])
FROM T
WHERE RN > NumToExclude AND RN <= cnt - NumToExclude;
The documentation states
TRIMMEAN(array, percent)
The TRIMMEAN function syntax has the following arguments:
Array Required. The array or range of values to trim and average.
Percent Required. The fractional number of data points to exclude
from the calculation. For example, if percent = 0.2, 4 points are
trimmed from a data set of 20 points (20 x 0.2): 2 from the top and 2
from the bottom of the set.
TRIMMEAN rounds the number of excluded data points down to the nearest
multiple of 2. If percent = 0.1, 10 percent of 30 data points equals 3
points. For symmetry, TRIMMEAN excludes a single value from the top
and bottom of the data set.
Something like the following should simulate the Excel function (demo).
For 0.2 the query returns 0.11107474 which is the same as Excel (and 0.35 returns 0,10455721 which is also the same).
DECLARE #Percent DECIMAL(2,2) = 0.2;
WITH T AS
(
SELECT [Data],
CAST(#Percent * COUNT(*) OVER() AS INT)/2 AS NumToExclude,
ROW_NUMBER() OVER (ORDER BY [Data] ASC) AS RNAsc,
ROW_NUMBER() OVER (ORDER BY [Data] DESC) AS RNDesc
FROM [dbo].[YourTable]
WHERE [Data] IS NOT NULL
)
SELECT AVG([Data])
FROM T
WHERE RNAsc > NumToExclude AND RNDesc > NumToExclude;