<?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 Calculated Table : Expand into multiple Rows in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Table-Expand-into-multiple-Rows/m-p/894778#M8017</link>
    <description>&lt;P&gt;I have to write Dax to make a calculated table which should collect all distinct years from date table and create something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2018 2017&lt;/P&gt;&lt;P&gt;2018 2018&lt;/P&gt;&lt;P&gt;2019 2018&lt;/P&gt;&lt;P&gt;2019 2019&lt;/P&gt;&lt;P&gt;2020 2019&lt;/P&gt;&lt;P&gt;2020 2020&lt;/P&gt;&lt;P&gt;2021 2020&lt;/P&gt;&lt;P&gt;2021 2021&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help, thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have a calculated table&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jan 2020 10:05:25 GMT</pubDate>
    <dc:creator>knowparthshah</dc:creator>
    <dc:date>2020-01-09T10:05:25Z</dc:date>
    <item>
      <title>Calculated Table : Expand into multiple Rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Table-Expand-into-multiple-Rows/m-p/894778#M8017</link>
      <description>&lt;P&gt;I have to write Dax to make a calculated table which should collect all distinct years from date table and create something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2018 2017&lt;/P&gt;&lt;P&gt;2018 2018&lt;/P&gt;&lt;P&gt;2019 2018&lt;/P&gt;&lt;P&gt;2019 2019&lt;/P&gt;&lt;P&gt;2020 2019&lt;/P&gt;&lt;P&gt;2020 2020&lt;/P&gt;&lt;P&gt;2021 2020&lt;/P&gt;&lt;P&gt;2021 2021&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help, thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have a calculated table&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 10:05:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Table-Expand-into-multiple-Rows/m-p/894778#M8017</guid>
      <dc:creator>knowparthshah</dc:creator>
      <dc:date>2020-01-09T10:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Table : Expand into multiple Rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Table-Expand-into-multiple-Rows/m-p/895500#M8054</link>
      <description>&lt;P&gt;Well this was a fun question to answer because I had to think of a strategy to get 2 rows per unique year in the date table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, I found a solution for you. I have a date table (DateTable2) from 1/1/2018 till 31/12/2022. THen I create the following&amp;nbsp;&lt;STRONG&gt;calculated table&lt;/STRONG&gt; for it:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CalcTable = 
VAR _DateTableWIthYears = ADDCOLUMNS(DateTable2, "Year", YEAR([Date]))
VAR _rankedTable = ADDCOLUMNS(_DateTableWIthYears, 
    "RankWithinYear", RANKX(FILTER(_DateTableWIthYears, [Year] = EARLIER([Year])), [Date]))
VAR _filterTopTwoPerYear = FILTER(_rankedTable, [RankWithinYear] &amp;lt;3)
VAR _addPrevYear = ADDCOLUMNS(_filterTopTwoPerYear, "SecondColumn", 
    IF([RankWithinYear] = 1, [Year], [Year] -1))
RETURN
SELECTCOLUMNS(_addPrevYear, "Year1", [Year], "Year2", [SecondColumn])&lt;/LI-CODE&gt;&lt;P&gt;This is not optimized but I wrote it like you could easily follow the logic behind it. It results in the following table:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Let me know if this works for you! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Djerro123&lt;/P&gt;&lt;P&gt;-------------------------------&lt;/P&gt;&lt;P&gt;If this answered your question, please &lt;STRONG&gt;mark it as the Solution&lt;/STRONG&gt;. This also helps others to find what they are looking for.&lt;/P&gt;&lt;P&gt;Keep those &lt;STRONG&gt;thumbs up&lt;/STRONG&gt; coming! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 21:27:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Table-Expand-into-multiple-Rows/m-p/895500#M8054</guid>
      <dc:creator>JarroVGIT</dc:creator>
      <dc:date>2020-01-09T21:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Table : Expand into multiple Rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Table-Expand-into-multiple-Rows/m-p/896317#M8072</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="137611" data-lia-user-login="JarroVGIT" class="lia-mention lia-mention-user"&gt;JarroVGIT&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks for the answer.&lt;/P&gt;&lt;P&gt;Even I figured out a way to acheive this.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;DateCYPY =
SELECTCOLUMNS (
    ADDCOLUMNS (
        GENERATEALL (
            VALUES ( 'Date'[Year] ),
            DATATABLE ( "type", STRING, { { "m" }, { "m-1" } } )
        ),
        "visibleY", IF ( [type] = "m", VALUE ( 'Date'[Year] ), 'Date'[Year] - 1 )
    ),
    "SelectedYear", 'Date'[Year],
    "VisibleYear", [visibleY]
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 11:41:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Table-Expand-into-multiple-Rows/m-p/896317#M8072</guid>
      <dc:creator>knowparthshah</dc:creator>
      <dc:date>2020-01-10T11:41:09Z</dc:date>
    </item>
  </channel>
</rss>

