<?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 Filter rows in a measure in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-rows-in-a-measure/m-p/1463440#M27649</link>
    <description>&lt;P&gt;I calculate an average value, but not all rows are filled in the original data. These I want to filter this and only return rows containing data in all columns.&lt;/P&gt;&lt;P&gt;Here the data after the caluculation of the average:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I can achieve this by setting a filter in the "filter pane" in the Desktop App.&lt;/P&gt;&lt;P&gt;But, how can I do this in DAX?&lt;/P&gt;&lt;P&gt;Here my code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;LocalCountOfAccicentsAvg = 
VAR Known =
    FILTER (
        SELECTCOLUMNS (
            ALLSELECTED ('Date'[Date]),
            "Known[X]", 'Date'[Date],
            "Known[Y]", CALCULATE(sum(KpiData[LocalCountOfAccidents]))
        ),
        AND ( 
            NOT ( ISBLANK ( Known[X] ) ), 
            NOT ( ISBLANK ( Known[Y] ) )
        )
    )
VAR Count_Items =
    COUNTROWS ( Known )
VAR Sum_X = SUMX ( Known, Known[X] )
VAR Sum_X2 = SUMX ( Known, Known[X] ^ 2 )
VAR Sum_Y = SUMX ( Known, Known[Y] )
VAR Sum_XY = SUMX ( Known, Known[X] * Known[Y] )
VAR Average_X = AVERAGEX ( Known, Known[X] )
VAR Average_Y = AVERAGEX ( Known, Known[Y] )
VAR Slope = DIVIDE (
        Count_Items * Sum_XY - Sum_X * Sum_Y,
        Count_Items * Sum_X2 - Sum_X ^ 2
    )
VAR Intercept = Average_Y - Slope * Average_X
VAR AllData = SUMX ( DISTINCT ( 'Date'[Date] ),
    Intercept + Slope * 'Date'[Date])
RETURN AllData &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 29 Oct 2020 12:59:39 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-10-29T12:59:39Z</dc:date>
    <item>
      <title>Filter rows in a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-rows-in-a-measure/m-p/1463440#M27649</link>
      <description>&lt;P&gt;I calculate an average value, but not all rows are filled in the original data. These I want to filter this and only return rows containing data in all columns.&lt;/P&gt;&lt;P&gt;Here the data after the caluculation of the average:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I can achieve this by setting a filter in the "filter pane" in the Desktop App.&lt;/P&gt;&lt;P&gt;But, how can I do this in DAX?&lt;/P&gt;&lt;P&gt;Here my code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;LocalCountOfAccicentsAvg = 
VAR Known =
    FILTER (
        SELECTCOLUMNS (
            ALLSELECTED ('Date'[Date]),
            "Known[X]", 'Date'[Date],
            "Known[Y]", CALCULATE(sum(KpiData[LocalCountOfAccidents]))
        ),
        AND ( 
            NOT ( ISBLANK ( Known[X] ) ), 
            NOT ( ISBLANK ( Known[Y] ) )
        )
    )
VAR Count_Items =
    COUNTROWS ( Known )
VAR Sum_X = SUMX ( Known, Known[X] )
VAR Sum_X2 = SUMX ( Known, Known[X] ^ 2 )
VAR Sum_Y = SUMX ( Known, Known[Y] )
VAR Sum_XY = SUMX ( Known, Known[X] * Known[Y] )
VAR Average_X = AVERAGEX ( Known, Known[X] )
VAR Average_Y = AVERAGEX ( Known, Known[Y] )
VAR Slope = DIVIDE (
        Count_Items * Sum_XY - Sum_X * Sum_Y,
        Count_Items * Sum_X2 - Sum_X ^ 2
    )
VAR Intercept = Average_Y - Slope * Average_X
VAR AllData = SUMX ( DISTINCT ( 'Date'[Date] ),
    Intercept + Slope * 'Date'[Date])
RETURN AllData &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 12:59:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-rows-in-a-measure/m-p/1463440#M27649</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-29T12:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Filter rows in a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-rows-in-a-measure/m-p/1464370#M27689</link>
      <description>&lt;P&gt;I think the only issue with your code is not having the [ ]&amp;nbsp; around your table names in the ISBLANKs.&amp;nbsp; I would not use [] in your virtual column names, to simplify things.&amp;nbsp; I would just use "KnownY" and "KnownX" when naming your columns in the SELECTCOLUMNS.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Pat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 22:48:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filter-rows-in-a-measure/m-p/1464370#M27689</guid>
      <dc:creator>mahoneypat</dc:creator>
      <dc:date>2020-10-29T22:48:08Z</dc:date>
    </item>
  </channel>
</rss>

