<?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 Dynamic table / context in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563471#M137366</link>
    <description>&lt;P&gt;Hello, I dynamic table as 'virtual' table or DAX table that will be re-calculated everytime a slicer selection is changing. It's not someting I can do on Power Query / to be refreshed with the dataset.&lt;BR /&gt;The DAX creating the table is working when I evaluating it, I think I'm just failing to understand who the context will work in that case.&lt;/P&gt;</description>
    <pubDate>Fri, 01 Dec 2023 16:48:23 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-12-01T16:48:23Z</dc:date>
    <item>
      <title>DAX Dynamic table / context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563294#M137357</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm getting stuck on a DAX formula when creating dynamic table based on this requirement:&lt;/P&gt;&lt;P&gt;-Getting all rows where the [AsOfDate] is lesser or equal to the date selected&lt;/P&gt;&lt;P&gt;-Getting all rows where the [Launch Year]-1 is equal to the year of the date selected&lt;/P&gt;&lt;P&gt;-Only getting latest / MAX [AsOfDate]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;For example:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I first created the logic in SQL since I'm more conformable than DAX then try to translate it:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CREATE TABLE #TemporaryTable 
(
   LaunchYear INT
    ,Period INT
    ,AsOfDate Date
    ,BCount INT
    ,ID VARCHAR(4)
);

INSERT INTO #TemporaryTable (LaunchYear,Period,AsOfDAte,BCount,ID) VALUES ('2022','1','2/1/2022','12','ASD')
,('2022','2','3/1/2022','5','ASD')
,('2022','3','4/1/2022','3','ASD')
,('2022','4','5/1/2022','2','ASD')
,('2022','5','6/1/2022','123','ASD')
,('2022','6','7/1/2022','14','ASD')
,('2022','7','8/1/2022','16','ASD')
,('2022','8','9/1/2022','1','ASD')
,('2022','1','6/1/2022','9','FGH')
,('2022','2','7/1/2022','3','FGH')
,('2022','3','9/1/2022','4','FGH')
,('2022','1','11/1/2022','12','JKL')
,('2022','2','12/1/2022','5','JKL')
,('2022','3','1/1/2023','3','JKL')
,('2022','4','2/1/2023','2','JKL')
,('2023','1','1/1/2023','0','XXX')

DECLARE @DateVar DATE = '2023-01-01';
--'2023-02-01';
--'2023-01-01';

SELECT LaunchYear
    ,Period
    ,AsOfDAte
    ,BCount
    ,ID
FROM (
    SELECT *
        ,ROW_NUMBER() OVER(PARTITION BY ID ORDER BY ID, AsOfDate DESC) RowNb
    FROM #TemporaryTable
    WHERE AsOfDate &amp;lt;= @DateVar
    AND LaunchYear = YEAR(@DateVar) -1
) A
WHERE RowNb = 1

DROP TABLE #TemporaryTable;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Above SQL is behaving as expected and I arrived to this DAX formula:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Dynamic Table = 
    
    VAR FilterTable = FILTER(
	    'Sheet1',
		'Sheet1'[AsOfDate] &amp;lt;= [DateSelected] &amp;amp;&amp;amp; 'Sheet1'[LaunchYear] = YEAR([DateSelected])-1
    )

    VAR AddRowNumber = ADDCOLUMNS(
        FilterTable,
        "RowNb",
            ROWNUMBER (
                FilterTable,
                ORDERBY ( 'Sheet1'[ID], ASC, Sheet1[AsOfDate], DESC),
                PARTITIONBY ( 'Sheet1'[ID])
            )
    )
    
    VAR FilterFirstRow = FILTER(AddRowNumber,[RowNb]=1)

    VAR Result = SELECTCOLUMNS(
        FilterFirstRow,
        "RowNb",[RowNb],
        "AsOfDate",Sheet1[AsOfDate],
        "BCount",Sheet1[BCount],
        "ID",Sheet1[ID],
        "LaunchYear",Sheet1[LaunchYear],
        "Period",Sheet1[Period]
    )

    RETURN  Result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's working fine when I evaluate it and 'hardcode' the date that is filtered:&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;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it's not working when I create it on the report view:&lt;/P&gt;&lt;P&gt;- DateSelected measure seems correct&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- DateSelected = &lt;SPAN&gt;SELECTEDVALUE&lt;SPAN&gt;(&lt;SPAN&gt;Sheet1&lt;SPAN&gt;[AsOfDate]&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;- Tab result is all wrong&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The slicer is having a Year-Month column from my Date table that seems to have a proper relationship with the 'Sheet1' table&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;&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;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;SPAN&gt;&lt;SPAN class=""&gt;I guess my issue is somewhere around my DateSelected measure / relationship with the Date table not able to have the correct context but I don't understand why obviously.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2023 14:51:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563294#M137357</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-12-01T14:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Dynamic table / context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563299#M137358</link>
      <description>&lt;P&gt;pbix and excel source file:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;&lt;A href="https://file.io/BnMWDSdfQ5gQ" target="_blank"&gt;https://file.io/BnMWDSdfQ5gQ&lt;/A&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Fri, 01 Dec 2023 14:55:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563299#M137358</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-12-01T14:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Dynamic table / context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563466#M137364</link>
      <description>&lt;P&gt;There's no such thing as a "dynamic" table in Power BI. There are computed tables, but they are computed on the refresh (load) of the model, so the content will not take into account any slicers or filters in a report.&lt;BR /&gt;Having a SQL background myself, I have found that is not always helpfull in understanding Power BI concepts.&lt;BR /&gt;So my advice is not to focus on the SQL equivalent but focus on the input data and the modeling of that and the required report output.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2023 16:44:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563466#M137364</guid>
      <dc:creator>sjoerdvn</dc:creator>
      <dc:date>2023-12-01T16:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Dynamic table / context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563471#M137366</link>
      <description>&lt;P&gt;Hello, I dynamic table as 'virtual' table or DAX table that will be re-calculated everytime a slicer selection is changing. It's not someting I can do on Power Query / to be refreshed with the dataset.&lt;BR /&gt;The DAX creating the table is working when I evaluating it, I think I'm just failing to understand who the context will work in that case.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2023 16:48:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563471#M137366</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-12-01T16:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Dynamic table / context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563504#M137368</link>
      <description>&lt;P&gt;you can try adding two measures like below, and then create a visual with these measures and the ID, LaunchYear and AsOfDate columns (do NOT add BCount and Period as columns!)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last BCount = CALCULATE(LASTNONBLANKVALUE('Date'[Date],MAX(Sheet1[BCount]), ALL('Date'), 'Date'[Date]&amp;lt;MAX('Date'[Date]))

Last Period = CALCULATE(LASTNONBLANKVALUE('Date'[Date],MAX(Sheet1[Period]), ALL('Date'), 'Date'[Date]&amp;lt;MAX('Date'[Date]))&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 01 Dec 2023 17:03:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563504#M137368</guid>
      <dc:creator>sjoerdvn</dc:creator>
      <dc:date>2023-12-01T17:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Dynamic table / context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563746#M137377</link>
      <description>&lt;P&gt;&amp;nbsp;A colleague of mine found working and more elegant solution. No need to create a DAX table, just to get the RANK in a measure, to filter the visuals accordingly (rank = 1) and to remove the relationship with the Data table.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;Rank = 
ROWNUMBER (
    FILTER(
        ALL(Sheet1),
        [AsOfDate] &amp;lt;= MINX(ALLSELECTED('Date'), [Start of Month])
            &amp;amp;&amp;amp; [LaunchYear] = MINX(ALLSELECTED('Date'), [Year]) - 1
    ),
    ORDERBY([AsOfDate], DESC),
    LAST,
    PARTITIONBY([ID])
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2023 21:13:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3563746#M137377</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-12-01T21:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Dynamic table / context</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3566380#M137483</link>
      <description>&lt;P&gt;I see that the visual filter on Rank will work, but in general that might not be the best performing solution. I was a bit to quick in posting my (untested) solution, which I think should be:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last BCount = CALCULATE(LASTNONBLANKVALUE('Sheet1'[AsOfDate],MAX(Sheet1[BCount]), ALL('Date'), 'Date'[Date]&amp;lt;MAX('Date'[Date]))

Last Period = CALCULATE(LASTNONBLANKVALUE('Sheet1'[AsOfDate],MAX(Sheet1[Period]), ALL('Date'), 'Date'[Date]&amp;lt;MAX('Date'[Date]))&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 04 Dec 2023 14:47:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Dynamic-table-context/m-p/3566380#M137483</guid>
      <dc:creator>sjoerdvn</dc:creator>
      <dc:date>2023-12-04T14:47:57Z</dc:date>
    </item>
  </channel>
</rss>

