<?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: DAX calculated column only working when variables used in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-calculated-column-only-working-when-variables-used/m-p/952059#M10731</link>
    <description>&lt;P&gt;Well, I have solved the problem myself just a short time after posting!&lt;/P&gt;&lt;P&gt;In my first attempt at the calculated column, I used [StoreName], but the problem is this &lt;EM&gt;&lt;STRONG&gt;unqualified&lt;/STRONG&gt;&lt;/EM&gt; column name is ambiguous and could refer to either Roster[StoreName] or&amp;nbsp;RosterList[StoreName]. I was assuming that because this was in a calculated column expression, it would default to the "current" table (which I guess is true when it's assigned to a VAR outside of the FILTER function) ... i.e. the implicit row context of the calculation. This seems to be wrong.&lt;/P&gt;&lt;P&gt;The simple fix is to qualify the column reference (also for [Date] though it's not ambiguous, but for clarity it should be qualified!)&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;Rostered Employee = 
CONCATENATEX(
    SELECTCOLUMNS(
        FILTER(Roster,
            // Wrong ... [StoreName] = Roster[StoreName]
            // Right ...
            RosterList[StoreName] = Roster[StoreName]
            &amp;amp;&amp;amp; RosterList[Date] &amp;gt;= Roster[StartDate]
            &amp;amp;&amp;amp; RosterList[Date] &amp;lt;= Roster[EndDate]
        )
        , "Employee"
        , [Employee]
    ),
    [Employee],
    ", "
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is now giving the correct results! Thanks for anyone who viewed it so far, and hopefully this may help others who make the same mistake that I did &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Feb 2020 04:45:14 GMT</pubDate>
    <dc:creator>rbbi</dc:creator>
    <dc:date>2020-02-28T04:45:14Z</dc:date>
    <item>
      <title>DAX calculated column only working when variables used</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-calculated-column-only-working-when-variables-used/m-p/952037#M10726</link>
      <description>&lt;P&gt;I'm trying to generate data using DAX tables and columns. Perhaps not the ideal way to do this, but helpful in my situation. I just don't understand why my calculated column doesn't work unless I assign a VARiable with a value from the current row for StoreName.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The PBIX file can be downloaded here:&amp;nbsp;&lt;A href="https://github.com/RodAtBurkeDataConsulting/PowerBI/blob/master/Roster.pbix" target="_blank"&gt;https://github.com/RodAtBurkeDataConsulting/PowerBI/blob/master/Roster.pbix&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the tables:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dates&lt;/STRONG&gt;: a list of dates&lt;BR /&gt;&lt;STRONG&gt;Stores&lt;/STRONG&gt;: a list of stores&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Roster&lt;/STRONG&gt;: a list of employees and date ranges they will be working at each store&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RosterList&lt;/STRONG&gt;: &lt;EM&gt;&lt;STRONG&gt;CrossJoin&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;of Dates and Stores, then add a calculated column to show the employees at each store on each date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not defining any relationships, just using DAX.&lt;/P&gt;&lt;P&gt;The DAX is pretty simple:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;Dates = CALENDAR("1 Jan 2020","10 Jan 2020")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;Stores = DATATABLE("StoreName", STRING, {{"Fish'n'Chips"},{"Burger Joint"}})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;Roster = DATATABLE("Employee", STRING, "StoreName", STRING, "StartDate", DATETIME, "EndDate", DATETIME,
{
    {"Jane", "Burger Joint", "1 Jan 2020", "3 Jan 2020"},
    {"Jane", "Fish'n'Chips", "2 Jan 2020", "4 Jan 2020"},
    {"Fred", "Fish'n'Chips", "2 Jan 2020", "2 Jan 2020"},
    {"Fred", "Burger Joint", "6 Jan 2020", "9 Jan 2020"}
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;RosterList = 
SELECTCOLUMNS(
    CROSSJOIN(Dates, Stores),
    "Sort", Stores[StoreName] &amp;amp; " " &amp;amp; FORMAT(Dates[Date],"yyyyMMdd"), // just for sorting the display
    "Date", Dates[Date],
    "StoreName", Stores[StoreName]
    )​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next I add a calculated column that finds the employee (or employees) who are rostered on for each date, based on the date range in the roster table. Note that relationships or LOOKUP() can't be used because &lt;STRONG&gt;(a)&lt;/STRONG&gt; the "join" is based on two columns, not one, and &lt;STRONG&gt;(b)&lt;/STRONG&gt; the join is based on the single Date value from the RosterList table falling within the &lt;STRONG&gt;range&lt;/STRONG&gt; of dates on each roster row. SO, I'm using FILTER() to filter the Roster table to get rows matching the store and where Dare is within the Roster row's date range, and CONCATENATEX() to join values together if there's more than one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my first attempt at the calulated column that gives the wrong results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;Rostered Employee WRONG = 
CONCATENATEX(
    SELECTCOLUMNS(
        FILTER(Roster,
            [StoreName] = Roster[StoreName]
            &amp;amp;&amp;amp; [Date] &amp;gt;= Roster[StartDate]
            &amp;amp;&amp;amp; [Date] &amp;lt;= Roster[EndDate]
        )
        , "Employee"
        , [Employee]
    ),
    [Employee],
    ", "
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this gives the wrong results, with Jane appearing mulitple times on the same row, and Fred appearing in Fish'n'Chips on days where he's only rostered for Burger Joint and other errors shown here:&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;Now, if I make one small change ... assign [StoreName] to a VAR and use that in the FILTER, it gives the correct values ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;Rostered Employee with VARs = 
VAR s = [StoreName]
RETURN
CONCATENATEX(
    SELECTCOLUMNS(
        FILTER(Roster,
            s = Roster[StoreName]
            &amp;amp;&amp;amp; [Date] &amp;gt;= Roster[StartDate]
            &amp;amp;&amp;amp; [Date] &amp;lt;= Roster[EndDate]
        )
        , "Employee"
        , [Employee]
    ),
    [Employee],
    ", "
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;I just don't understand why assigning [StoreName] to a VAR is any different to using [StoreName] in the filter.&lt;/P&gt;&lt;P&gt;I thought [StoreName] on with no table qualification should be referencing the current row's value of StoreName??&lt;/P&gt;&lt;P&gt;Hoping someone can explain this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 03:57:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-calculated-column-only-working-when-variables-used/m-p/952037#M10726</guid>
      <dc:creator>rbbi</dc:creator>
      <dc:date>2020-02-28T03:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: DAX calculated column only working when variables used</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-calculated-column-only-working-when-variables-used/m-p/952059#M10731</link>
      <description>&lt;P&gt;Well, I have solved the problem myself just a short time after posting!&lt;/P&gt;&lt;P&gt;In my first attempt at the calculated column, I used [StoreName], but the problem is this &lt;EM&gt;&lt;STRONG&gt;unqualified&lt;/STRONG&gt;&lt;/EM&gt; column name is ambiguous and could refer to either Roster[StoreName] or&amp;nbsp;RosterList[StoreName]. I was assuming that because this was in a calculated column expression, it would default to the "current" table (which I guess is true when it's assigned to a VAR outside of the FILTER function) ... i.e. the implicit row context of the calculation. This seems to be wrong.&lt;/P&gt;&lt;P&gt;The simple fix is to qualify the column reference (also for [Date] though it's not ambiguous, but for clarity it should be qualified!)&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;Rostered Employee = 
CONCATENATEX(
    SELECTCOLUMNS(
        FILTER(Roster,
            // Wrong ... [StoreName] = Roster[StoreName]
            // Right ...
            RosterList[StoreName] = Roster[StoreName]
            &amp;amp;&amp;amp; RosterList[Date] &amp;gt;= Roster[StartDate]
            &amp;amp;&amp;amp; RosterList[Date] &amp;lt;= Roster[EndDate]
        )
        , "Employee"
        , [Employee]
    ),
    [Employee],
    ", "
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is now giving the correct results! Thanks for anyone who viewed it so far, and hopefully this may help others who make the same mistake that I did &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 04:45:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-calculated-column-only-working-when-variables-used/m-p/952059#M10731</guid>
      <dc:creator>rbbi</dc:creator>
      <dc:date>2020-02-28T04:45:14Z</dc:date>
    </item>
  </channel>
</rss>

