<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic To **bleep** With MEDIAN in Quick Measures Gallery</title>
    <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/To-bleep-With-MEDIAN/m-p/1322755#M599</link>
    <description>&lt;P&gt;Here is an interesting one brought to us by&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="253647" data-lia-user-login="RiskyBiscuts" class="lia-mention lia-mention-user"&gt;RiskyBiscuts&lt;/a&gt;. Basically, you can't use MEDIAN to create columns. Why you may ask? Well, as elegantly explained by&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="41" data-lia-user-login="marcorusso" class="lia-mention lia-mention-user"&gt;marcorusso&lt;/a&gt;&amp;nbsp;, MEDIAN returns a Variant data type (as opposed to a decimal number according to the official Microsoft documentation). See the original thread here:&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Power-Query/quot-Expressions-that-yield-variant-data-type-quot-error-when/td-p/1320838/highlight/false" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Power-Query/quot-Expressions-that-yield-variant-data-type-quot-error-when/td-p/1320838/highlight/false.&lt;/A&gt;&amp;nbsp;Hence why you get the error "&lt;EM&gt;Expressions that yield variant data-type cannot be used to define calculated columns&lt;/EM&gt;". Which then leads to the mystery of why in the world are you hyphenating data type? I mean, I'm a consultant and we consultants over-hyphenate everything, but even I do not hyphenate data type. And another thing, shouldn't it be "&lt;EM&gt;Expressions that yield &lt;STRONG&gt;a&lt;/STRONG&gt; variant...&lt;/EM&gt;" Come on people, grammar! But, anyway, I digress.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh, and this also goes for MEDIANX, PERCENTILE.EXC, PERCENTILE.INC, PERCENTILEX.EXC and PERCENTILEX.INC. All useless for columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;Why does MEDIAN return a variant? Is Microsoft intentionally trying to make us cry tears of sadness and despair? It's probably because you incurred bad karma from &lt;A href="https://community.powerbi.com/t5/Community-Blog/Column-Level-Security/bc-p/1323097" target="_self"&gt;lying to your Power BI data model&lt;/A&gt;. I warned you that would happen. Or, could it be because you can do a median of strings, booleans and dates perhaps? Wouldn't that be cool if median supported...oh wait, nope, fail. Median doesn't support anything other than numbers apparently so that's not it. Lame.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Luckily though, if we remember our maths, we can brute force our way to victory to create a median in a column:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Median 1 = 
    VAR __Table = 
        ADDCOLUMNS(
            ADDCOLUMNS(
                'Table',
                "Above",COUNTROWS(FILTER('Table',[Unique Deviation]&amp;lt;EARLIER([Unique Deviation]))),
                "Below",COUNTROWS(FILTER('Table',[Unique Deviation]&amp;gt;EARLIER([Unique Deviation])))
            ),
            "Diff",ABS([Above]-[Below])
        )
    VAR __Min = MINX(__Table,[Diff])
RETURN
    MAXX(FILTER(__Table,[Diff]=__Min),[Unique Deviation])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could use&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="41" data-lia-user-login="marcorusso" class="lia-mention lia-mention-user"&gt;marcorusso&lt;/a&gt;'s a bit more elegant solution that still uses MEDIAN:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Median 2 = CONVERT(MEDIAN('Table'[Unique Deviation]),INTEGER)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="reportid hidden"&gt;eyJrIjoiODY2OWFkY2QtMjUwMS00MTllLWIxNTAtMjU4ZGViNWIzYWQ2IiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Aug 2020 15:20:38 GMT</pubDate>
    <dc:creator>Greg_Deckler</dc:creator>
    <dc:date>2020-08-25T15:20:38Z</dc:date>
    <item>
      <title>To **bleep** With MEDIAN</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/To-bleep-With-MEDIAN/m-p/1322755#M599</link>
      <description>&lt;P&gt;Here is an interesting one brought to us by&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="253647" data-lia-user-login="RiskyBiscuts" class="lia-mention lia-mention-user"&gt;RiskyBiscuts&lt;/a&gt;. Basically, you can't use MEDIAN to create columns. Why you may ask? Well, as elegantly explained by&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="41" data-lia-user-login="marcorusso" class="lia-mention lia-mention-user"&gt;marcorusso&lt;/a&gt;&amp;nbsp;, MEDIAN returns a Variant data type (as opposed to a decimal number according to the official Microsoft documentation). See the original thread here:&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Power-Query/quot-Expressions-that-yield-variant-data-type-quot-error-when/td-p/1320838/highlight/false" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Power-Query/quot-Expressions-that-yield-variant-data-type-quot-error-when/td-p/1320838/highlight/false.&lt;/A&gt;&amp;nbsp;Hence why you get the error "&lt;EM&gt;Expressions that yield variant data-type cannot be used to define calculated columns&lt;/EM&gt;". Which then leads to the mystery of why in the world are you hyphenating data type? I mean, I'm a consultant and we consultants over-hyphenate everything, but even I do not hyphenate data type. And another thing, shouldn't it be "&lt;EM&gt;Expressions that yield &lt;STRONG&gt;a&lt;/STRONG&gt; variant...&lt;/EM&gt;" Come on people, grammar! But, anyway, I digress.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh, and this also goes for MEDIANX, PERCENTILE.EXC, PERCENTILE.INC, PERCENTILEX.EXC and PERCENTILEX.INC. All useless for columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;Why does MEDIAN return a variant? Is Microsoft intentionally trying to make us cry tears of sadness and despair? It's probably because you incurred bad karma from &lt;A href="https://community.powerbi.com/t5/Community-Blog/Column-Level-Security/bc-p/1323097" target="_self"&gt;lying to your Power BI data model&lt;/A&gt;. I warned you that would happen. Or, could it be because you can do a median of strings, booleans and dates perhaps? Wouldn't that be cool if median supported...oh wait, nope, fail. Median doesn't support anything other than numbers apparently so that's not it. Lame.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Luckily though, if we remember our maths, we can brute force our way to victory to create a median in a column:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Median 1 = 
    VAR __Table = 
        ADDCOLUMNS(
            ADDCOLUMNS(
                'Table',
                "Above",COUNTROWS(FILTER('Table',[Unique Deviation]&amp;lt;EARLIER([Unique Deviation]))),
                "Below",COUNTROWS(FILTER('Table',[Unique Deviation]&amp;gt;EARLIER([Unique Deviation])))
            ),
            "Diff",ABS([Above]-[Below])
        )
    VAR __Min = MINX(__Table,[Diff])
RETURN
    MAXX(FILTER(__Table,[Diff]=__Min),[Unique Deviation])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could use&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="41" data-lia-user-login="marcorusso" class="lia-mention lia-mention-user"&gt;marcorusso&lt;/a&gt;'s a bit more elegant solution that still uses MEDIAN:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Median 2 = CONVERT(MEDIAN('Table'[Unique Deviation]),INTEGER)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="reportid hidden"&gt;eyJrIjoiODY2OWFkY2QtMjUwMS00MTllLWIxNTAtMjU4ZGViNWIzYWQ2IiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Aug 2020 15:20:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/To-bleep-With-MEDIAN/m-p/1322755#M599</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-08-25T15:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: To **bleep** With MEDIAN</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/To-bleep-With-MEDIAN/m-p/1338560#M604</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why should we simplify things just by using CONVERT, we can create columns within colunmns and in tables so everything get's really fun.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just kidding with you, sometimes we need to &lt;SPAN&gt;deconstruct things and return to our basic math thinking that way we can really understand what the functions are doing.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Very good post once more.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 12:15:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/To-bleep-With-MEDIAN/m-p/1338560#M604</guid>
      <dc:creator>MFelix</dc:creator>
      <dc:date>2020-09-01T12:15:28Z</dc:date>
    </item>
  </channel>
</rss>

