<?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 AverageX on a virtual table in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AverageX-on-a-virtual-table/m-p/1072564#M14969</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have spent a number of hour researching and not getting anywhere, if there is anybody that can help I would appreciate it!&lt;/P&gt;&lt;P&gt;I have a table of dates, which i am building a forecast measure for called 't'. I am trying to add the measure shown in grey on the picture to my table (unsuccesfully) because I cant seem to apply the correct filter to my virtual table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anybody suggest code that would allow me to put the figures in grey into my visual using DAX / virtual table only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code for my workbook (sample data):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromList(List.Dates(Date.From(DateTime.FixedLocalNow()), 14, #duration(1, 0, 0, 0)), Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Custom" = Table.SelectColumns(Table.AddColumn(Source, "t", each List.Repeat({[Column1]}, Number.RoundUp(Number.RandomBetween(50, 100)))), {"t"}),
    #"Expanded t" = Table.ExpandListColumn(#"Added Custom", "t"),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded t",{{"t", type date}})
in
    #"Changed Type"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dax calculated measure (Sx ? = where a i would like expected output to be returned:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Sx ? = //return the average of all "Sx Ix" by weekday
//t[t] = a list of dates
VAR _weekday = WEEKDAY(SELECTEDVALUE(t[t]), 2) //the weekday of each t[t]
VAR _t_by_date = //a summary of t grouped by t[t] with extra calculated a column called Sx Ix
    SUMMARIZE(
            t, t[t], "weekday", WEEKDAY(t[t]),
            "Sx Ix",
            DIVIDE(
                COUNTROWS(t), //a count of all rows grouped by t[t]
                CALCULATE(
                    COUNTROWS(t),
                    ALL(t), t[t] + 3 &amp;gt;= EARLIER(t[t]) &amp;amp;&amp;amp; t[t] - 3 &amp;lt;= EARLIER(t[t])
                ) / 7 //a rolling average of 7 days
            ) //the Sx Ix calculated column
    )
RETURN
    "?" 
    /*AVERAGEX(
        FILTER(
            SUMMARIZE('t by date', 't by date'[weekday], "Sx", AVERAGE('t by date'[Sx Ix])),
            't by date'[weekday] = _Weekday
        ),
        [Sx]
    )*/&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dax calculated table with calculated column (expected output):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;t by date = 
VAR _sx_ix = 
VAR _weekday = SELECTEDVALUE(t[weekday])
VAR _t_by_date = 
    SUMMARIZE(
            t, t[t], "weekday", WEEKDAY(t[t]),
            "Sx Ix",
            DIVIDE(
                COUNTROWS(t),
                CALCULATE(
                    COUNTROWS(t),
                    ALL(t), t[t]+3 &amp;gt;= EARLIER(t[t]) &amp;amp;&amp;amp; t[t]-3 &amp;lt;= EARLIER(t[t])
                ) / 7
            )
    )
RETURN
ADDCOLUMNS(
    _t_by_date,
    "Sx ?",
        "?" /*"want to add formulated column here"
            VAR _Weekday = WEEKDAY('t by date'[t])
                RETURN
                    AVERAGEX(
                        FILTER(
                            SUMMARIZE('t by date', 't by date'[weekday], "Sx", AVERAGE('t by date'[Sx Ix])),
                            't by date'[weekday] = _Weekday
                        ),
                    [Sx]
                    )*/
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 May 2020 11:29:20 GMT</pubDate>
    <dc:creator>mattio</dc:creator>
    <dc:date>2020-05-05T11:29:20Z</dc:date>
    <item>
      <title>AverageX on a virtual table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AverageX-on-a-virtual-table/m-p/1072564#M14969</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have spent a number of hour researching and not getting anywhere, if there is anybody that can help I would appreciate it!&lt;/P&gt;&lt;P&gt;I have a table of dates, which i am building a forecast measure for called 't'. I am trying to add the measure shown in grey on the picture to my table (unsuccesfully) because I cant seem to apply the correct filter to my virtual table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anybody suggest code that would allow me to put the figures in grey into my visual using DAX / virtual table only.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code for my workbook (sample data):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromList(List.Dates(Date.From(DateTime.FixedLocalNow()), 14, #duration(1, 0, 0, 0)), Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Custom" = Table.SelectColumns(Table.AddColumn(Source, "t", each List.Repeat({[Column1]}, Number.RoundUp(Number.RandomBetween(50, 100)))), {"t"}),
    #"Expanded t" = Table.ExpandListColumn(#"Added Custom", "t"),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded t",{{"t", type date}})
in
    #"Changed Type"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dax calculated measure (Sx ? = where a i would like expected output to be returned:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Sx ? = //return the average of all "Sx Ix" by weekday
//t[t] = a list of dates
VAR _weekday = WEEKDAY(SELECTEDVALUE(t[t]), 2) //the weekday of each t[t]
VAR _t_by_date = //a summary of t grouped by t[t] with extra calculated a column called Sx Ix
    SUMMARIZE(
            t, t[t], "weekday", WEEKDAY(t[t]),
            "Sx Ix",
            DIVIDE(
                COUNTROWS(t), //a count of all rows grouped by t[t]
                CALCULATE(
                    COUNTROWS(t),
                    ALL(t), t[t] + 3 &amp;gt;= EARLIER(t[t]) &amp;amp;&amp;amp; t[t] - 3 &amp;lt;= EARLIER(t[t])
                ) / 7 //a rolling average of 7 days
            ) //the Sx Ix calculated column
    )
RETURN
    "?" 
    /*AVERAGEX(
        FILTER(
            SUMMARIZE('t by date', 't by date'[weekday], "Sx", AVERAGE('t by date'[Sx Ix])),
            't by date'[weekday] = _Weekday
        ),
        [Sx]
    )*/&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dax calculated table with calculated column (expected output):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;t by date = 
VAR _sx_ix = 
VAR _weekday = SELECTEDVALUE(t[weekday])
VAR _t_by_date = 
    SUMMARIZE(
            t, t[t], "weekday", WEEKDAY(t[t]),
            "Sx Ix",
            DIVIDE(
                COUNTROWS(t),
                CALCULATE(
                    COUNTROWS(t),
                    ALL(t), t[t]+3 &amp;gt;= EARLIER(t[t]) &amp;amp;&amp;amp; t[t]-3 &amp;lt;= EARLIER(t[t])
                ) / 7
            )
    )
RETURN
ADDCOLUMNS(
    _t_by_date,
    "Sx ?",
        "?" /*"want to add formulated column here"
            VAR _Weekday = WEEKDAY('t by date'[t])
                RETURN
                    AVERAGEX(
                        FILTER(
                            SUMMARIZE('t by date', 't by date'[weekday], "Sx", AVERAGE('t by date'[Sx Ix])),
                            't by date'[weekday] = _Weekday
                        ),
                    [Sx]
                    )*/
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 11:29:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AverageX-on-a-virtual-table/m-p/1072564#M14969</guid>
      <dc:creator>mattio</dc:creator>
      <dc:date>2020-05-05T11:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: AverageX on a virtual table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AverageX-on-a-virtual-table/m-p/1072629#M14978</link>
      <description>&lt;P&gt;Sample data, expected output please.&amp;nbsp;Please see this post regarding How to Get Your Question Answered Quickly: &lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490" target="_blank"&gt;https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 11:21:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AverageX-on-a-virtual-table/m-p/1072629#M14978</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-05-05T11:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: AverageX on a virtual table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AverageX-on-a-virtual-table/m-p/1082995#M15384</link>
      <description>&lt;P&gt;Hi, yes thanks for that i did post the M code which contains the sample data as well as expected output as seen in the DAX examples.&lt;/P&gt;</description>
      <pubDate>Sun, 10 May 2020 20:48:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/AverageX-on-a-virtual-table/m-p/1082995#M15384</guid>
      <dc:creator>mattio</dc:creator>
      <dc:date>2020-05-10T20:48:47Z</dc:date>
    </item>
  </channel>
</rss>

