<?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: Two fact tables: with DATE and START_DATE &amp;amp; END_DATE columns - how to merge them? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Two-fact-tables-with-DATE-and-START-DATE-amp-END-DATE-columns/m-p/3673532#M142537</link>
    <description>&lt;P&gt;Glad to hear it helped. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2024 17:00:11 GMT</pubDate>
    <dc:creator>sevenhills</dc:creator>
    <dc:date>2024-02-01T17:00:11Z</dc:date>
    <item>
      <title>Two fact tables: with DATE and START_DATE &amp; END_DATE columns - how to merge them?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Two-fact-tables-with-DATE-and-START-DATE-amp-END-DATE-columns/m-p/3666389#M142141</link>
      <description>&lt;P&gt;Hi everyone!&lt;BR /&gt;&lt;BR /&gt;I have two fact tables with the sales data and I would like to merge and get rid of one of them.&lt;BR /&gt;&lt;BR /&gt;The structure looks as follows:&lt;BR /&gt;&lt;STRONG&gt;FACT_1:&lt;/STRONG&gt;&lt;EM&gt; dim1, dim2, dim3, dim4, &lt;U&gt;sales_date&lt;/U&gt;, price1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;FACT_2: &lt;/STRONG&gt;&lt;EM&gt;dim1, dim2, dim3, &lt;U&gt;start_date&lt;/U&gt;, &lt;U&gt;end_date&lt;/U&gt;, price2&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'd like to create an additional column in FACT_1 table (prefarably in PQ but not sure if it's possible, so a solution for the DAX calculation column would also be acceptable) to get the price2 value from the FACT_2 table for each row, where &lt;EM&gt;sales_date&lt;/EM&gt; is between the &lt;EM&gt;start_date&lt;/EM&gt; and &lt;EM&gt;end_date&lt;/EM&gt; (in the FACT_2 table there are more that one row for each combination of &lt;EM&gt;dim1, dim2&lt;/EM&gt; &amp;amp; &lt;EM&gt;dim3,&lt;/EM&gt;&amp;nbsp;with a different time range and &lt;EM&gt;price2&lt;/EM&gt; value).&lt;BR /&gt;&lt;BR /&gt;Having the&lt;EM&gt; price2&lt;/EM&gt; column in the FACT_1 table would be incredibly helpful because in some of the measures I have to iterate through the FACT_1 table - I could then refer directly to the value of the column created for each row.&lt;BR /&gt;&lt;BR /&gt;Any solution/idea highly appreciated! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 14:51:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Two-fact-tables-with-DATE-and-START-DATE-amp-END-DATE-columns/m-p/3666389#M142141</guid>
      <dc:creator>jagnejszyn</dc:creator>
      <dc:date>2024-01-29T14:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: Two fact tables: with DATE and START_DATE &amp; END_DATE columns - how to merge them?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Two-fact-tables-with-DATE-and-START-DATE-amp-END-DATE-columns/m-p/3666999#M142172</link>
      <description>&lt;P&gt;Not sure whether it is a good idea to bring different level of facts into one. It is a common scenario of type 2 dim data joining to fact i.e., yours like more as merge join on range of dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let us do this and see if it works for your needs.&lt;/P&gt;
&lt;P&gt;a) Assuming your fact2 data is matching one for every join else you may have to add some more logic.&lt;/P&gt;
&lt;P&gt;b) Adjust your &amp;gt;= and &amp;lt;= if needed as some use &amp;gt; or&amp;lt; in the join M query&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IP: Fact1&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IP: Fact2&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;M Query:&lt;/P&gt;
&lt;P&gt;Fact1 Table ... first two rows are your original source data. Rest is all I added to get the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsnMNQxLzClNVdIBsY2Q2MZIbBMY29BA1ysxT9fIwMgEzDNQitUhyxSX1GSQKcZAnqUluYY4FhTBnGJhgWqIEbIpRsjGGCGbY4ThJzMzSgzyTayEG2SuFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Dim1 = _t, Dim2 = _t, Dim3 = _t, Dim4 = _t, Sales_Date = _t, Price1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Dim1", type text}, {"Dim2", type text}, {"Dim3", type text}, {"Dim4", type text}, {"Sales_Date", type date}, {"Price1", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Dim1", "Dim2", "Dim3"}, Fact2, {"Dim1", "Dim2", "Dim3"}, "Fact2", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Custom", each let tt_Date = [Sales_Date] in Table.SelectRows([Fact2], each [Start_Date] &amp;lt;= tt_Date and tt_Date &amp;lt;= [End_Date])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Price2"}, {"Price2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Price2", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Fact2"})
in
    #"Removed Columns"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tip: You can use Table.Buffer() if there is a performance issue before #"Added Custom"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 22:26:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Two-fact-tables-with-DATE-and-START-DATE-amp-END-DATE-columns/m-p/3666999#M142172</guid>
      <dc:creator>sevenhills</dc:creator>
      <dc:date>2024-01-29T22:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Two fact tables: with DATE and START_DATE &amp; END_DATE columns - how to merge them?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Two-fact-tables-with-DATE-and-START-DATE-amp-END-DATE-columns/m-p/3673330#M142523</link>
      <description>&lt;P&gt;It worked, thank you so much! You're my hero! &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 15:50:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Two-fact-tables-with-DATE-and-START-DATE-amp-END-DATE-columns/m-p/3673330#M142523</guid>
      <dc:creator>jagnejszyn</dc:creator>
      <dc:date>2024-02-01T15:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Two fact tables: with DATE and START_DATE &amp; END_DATE columns - how to merge them?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Two-fact-tables-with-DATE-and-START-DATE-amp-END-DATE-columns/m-p/3673532#M142537</link>
      <description>&lt;P&gt;Glad to hear it helped. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2024 17:00:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Two-fact-tables-with-DATE-and-START-DATE-amp-END-DATE-columns/m-p/3673532#M142537</guid>
      <dc:creator>sevenhills</dc:creator>
      <dc:date>2024-02-01T17:00:11Z</dc:date>
    </item>
  </channel>
</rss>

