<?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 Re: Computing chi squared in Dax - missing values in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Computing-chi-squared-in-Dax-missing-values/m-p/3856489#M150657</link>
    <description>&lt;P&gt;That function requires the input X the sum ofvthe squares of the variation from the expected values, which is the number I'm &amp;nbsp;trying to compute.&lt;/P&gt;</description>
    <pubDate>Sun, 21 Apr 2024 05:23:45 GMT</pubDate>
    <dc:creator>Nyarlathorep300</dc:creator>
    <dc:date>2024-04-21T05:23:45Z</dc:date>
    <item>
      <title>Computing chi squared in Dax - missing values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Computing-chi-squared-in-Dax-missing-values/m-p/3852688#M150517</link>
      <description>&lt;P&gt;I have a regularly changing dataset, on which I'm trying to create a measure that computes chi squared statistics. I want a measure so the underlying data can be filtered and the statistic will be recalcualted accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The raw data is surey responses for people exiting, one row per person, that hold personal information about the individual and information about motives for exiting. &amp;nbsp;I made a measure that summarizes the table by a pair of characteristics, computes the expected values, then the the mean squared variation statistic, and then sums over the rows to get the chi squared statistics.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Table = ADDCOLUMNS ( 
                  ADDCOLUMNS (
                       SUMMARIZE (
                             LeavingFactorMaster,LeavingFactorMaster[Ethnicity], LeavingFactorMaster[LeavingFactor],
                             "people", count(LeavingFactorMaster[id])
                          ), 
                         "EFx1", CALCULATE(count(LeavingFactorMaster[id]),ALL(LeavingFactorMaster[Ethnicity])),
                          "EFx2", CALCULATE(count(LeavingFactorMaster[id]),ALL(LeavingFactorMaster[LeavingFactor])),
                           "EFx3", CALCULATE(count(LeavingFactorMaster[id]),ALL(LeavingFactorMaster[LeavingFactor],LeavingFactorMaster[Ethnicity])),
                            "EFx4", divide(                                                  CALCULATE(count(LeavingFactorMaster[id]),ALL(LeavingFactorMaster[Ethnicity]))*                                            	            	CALCULATE(count(LeavingFactorMaster[id]),ALL(LeavingFactorMaster[LeavingFactor])),                                        	CALCULATE(count(LeavingFactorMaster[id]),ALL(LeavingFactorMaster[LeavingFactor],LeavingFactorMaster[Ethnicity]))
                             )
                   ), 
                   "EFx5", divide(([people]-[EFx4])^2,[EFx4])
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So far so good, EFx5 looks about right, but testing the output, there is an issue. If zero people in a ethinc group gave a particular LeavingFactor answer then there is no row in the summarized table, however this combination can have a non zero expected value. This means that the chi squared stat is lower than it should be.&lt;BR /&gt;I've tried to gap fill using code like this.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;table2 =

var _tabl = ADDCOLUMNS(                         

                                GROUPBY(

                                                UNION (

                                                                SUMMARIZE (

                                                                                LeavingFactorMaster,LeavingFactorMaster[Ethnicity], LeavingFactorMaster[LeavingFactor],

                                                                                "pp", count(LeavingFactorMaster[id])

                                                                ),

                                                                ADDCOLUMNS(

                                                                                CROSSJOIN(

                                                                                                VALUES(LeavingFactorMaster[Ethnicity]), VALUES(LeavingFactorMaster[LeavingFactor])

                                                                                ),

                                                                "pp", 0)

                                                ),

                                                [Ethnicity],[LeavingFactor],

                                                "people1",sumx(CURRENTGROUP(),[pp])

                                ), "EFx1", 1

)

return _tabl&lt;/LI-CODE&gt;&lt;P&gt;This does ensure that the zero rows are added, but I can't work out any way of doing calculations on "people1" to compute the chi-squared statistic like the first chunk of code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my question is am I on the right track? Is can this be tweaked to work? If not, is there an different approach that will compute the chi-squared stat correctly?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2024 07:21:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Computing-chi-squared-in-Dax-missing-values/m-p/3852688#M150517</guid>
      <dc:creator>Nyarlathorep300</dc:creator>
      <dc:date>2024-04-19T07:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Computing chi squared in Dax - missing values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Computing-chi-squared-in-Dax-missing-values/m-p/3854887#M150621</link>
      <description>&lt;P&gt;Any particular reason for not using the built-in function?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/dax/chisq-dist-function-dax" target="_blank"&gt;CHISQ.DIST function (DAX) - DAX | Microsoft Learn&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Apr 2024 00:28:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Computing-chi-squared-in-Dax-missing-values/m-p/3854887#M150621</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-04-20T00:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Computing chi squared in Dax - missing values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Computing-chi-squared-in-Dax-missing-values/m-p/3856489#M150657</link>
      <description>&lt;P&gt;That function requires the input X the sum ofvthe squares of the variation from the expected values, which is the number I'm &amp;nbsp;trying to compute.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Apr 2024 05:23:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Computing-chi-squared-in-Dax-missing-values/m-p/3856489#M150657</guid>
      <dc:creator>Nyarlathorep300</dc:creator>
      <dc:date>2024-04-21T05:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Computing chi squared in Dax - missing values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Computing-chi-squared-in-Dax-missing-values/m-p/3857094#M150679</link>
      <description>&lt;LI-CODE lang="markup"&gt; If zero people in a ethnic group gave a particular LeavingFactor answer&lt;/LI-CODE&gt;
&lt;P&gt;Is that because there were no leavers in that group or because they left but didn't fill the survey?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can consider using COALESCE to fill voids.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Apr 2024 20:06:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Computing-chi-squared-in-Dax-missing-values/m-p/3857094#M150679</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-04-21T20:06:59Z</dc:date>
    </item>
  </channel>
</rss>

