<?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: Output rows based on matching date time intervals in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Output-rows-based-on-matching-date-time-intervals/m-p/1749141#M36405</link>
    <description>&lt;P&gt;Do you really need second level accuracy (as in deals 321 and 654) or is minute level accuracy sufficient?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Asking because the standard answer ("Use GENERATESERIES and INTERSECT") would be much tougher to do on seconds level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an alternative approach.&amp;nbsp; In your "Modified Table A"&amp;nbsp; add a calculated column:&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;deal_id = 
var t = 'Modified Table A'[timestamp]
var p = 'Modified Table A'[product_id]
var d = CALCULATETABLE('Modified Table B','Modified Table B'[start_date_time]&amp;lt;=t,'Modified Table B'[end_date_time]&amp;gt;=t,'Modified Table B'[product_id]=p)
return CONCATENATEX(d,'Modified Table B'[deal_id],"")&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;That will give you the deal ID for any order that has a deal.&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;However, when trying to link the tables via the deal_id field you will (not surprisingly) encounter a circular reference error.&amp;nbsp; That means it would be better to implement that calculated column in Power Query instead.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc/RDYAgDEXRVUy/SewrFNFViPuvYVuCmuhfQw630DtBMiXCqquwYGkH+GD2I8lF69Z2OlMnG4OVwVANDbe3rWrJgnDuXzmLQf967t21uVZcfnI2BoMMVz0XzmImAQlnt4bT2/Gfm2uf335fd14=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [order_id = _t, timestamp = _t, product_id = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"timestamp", type datetime}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"product_id"}, #"Modified Table B", {"product_id"}, "Modified Table B", JoinKind.LeftOuter),
    #"Expanded Modified Table B" = Table.ExpandTableColumn(#"Merged Queries", "Modified Table B", {"deal_id", "start_date_time", "end_date_time"}, {"deal_id", "start_date_time", "end_date_time"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Modified Table B", "Match", each if [start_date_time]&amp;lt;=[timestamp] and [timestamp]&amp;lt;= [end_date_time] then 1 else 0),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom", {{"Match", 0}}),
    #"Added Custom1" = Table.AddColumn(#"Replaced Errors", "d", each if [Match]=1 then [deal_id] else null),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"order_id", "timestamp", "product_id", "d"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"d", "deal_id"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"deal_id", type text}})
in
    #"Changed Type1"&lt;/LI-CODE&gt;
&lt;P&gt;which then allows us to link the tables and produce the expected outcome&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 27 Mar 2021 03:19:10 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2021-03-27T03:19:10Z</dc:date>
    <item>
      <title>Output rows based on matching date time intervals</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Output-rows-based-on-matching-date-time-intervals/m-p/1746582#M36331</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help on the same requirement which is handled in the below post, but when there is a many to many relationship.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Desktop/DAX-Flag-order-if-timestamp-is-in-between-2-dates-and-product-id/m-p/1615236#M652054" target="_blank" rel="noopener"&gt;Solved: DAX: Flag order if timestamp is in between 2 dates... - Microsoft Power BI Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Table B will have multiple deal intervals on the same product differentiated using a timestamp.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Modified Table B&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;deal_id&lt;/TD&gt;&lt;TD&gt;start_date_time&lt;/TD&gt;&lt;TD&gt;end_date_time&lt;/TD&gt;&lt;TD&gt;product_id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;02.01.2021 10:00:000&lt;/TD&gt;&lt;TD&gt;04.01.2021 14:00:00&lt;/TD&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;05.01.2021 8:00:00&lt;/TD&gt;&lt;TD&gt;05.01.2021 8:25:00&lt;/TD&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;05.01.2021 10:00:00&lt;/TD&gt;&lt;TD&gt;05.01.2021 10:25:00&lt;/TD&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Modified Table A - order positions (multiple orders on same product at different times)&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;order_id&lt;/TD&gt;&lt;TD&gt;timestamp&lt;/TD&gt;&lt;TD&gt;product_id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;05.01.2021 8:10:00&lt;/TD&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;456&lt;/TD&gt;&lt;TD&gt;04.01.2021 16:00:00&lt;/TD&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;TD&gt;05.01.2021 10:15:00&lt;/TD&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;321&lt;/TD&gt;&lt;TD&gt;08.01.2021 8:20:15&lt;/TD&gt;&lt;TD&gt;987654321&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;654&lt;/TD&gt;&lt;TD&gt;12.01.2021 6:15:15&lt;/TD&gt;&lt;TD&gt;345876112&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;987&lt;/TD&gt;&lt;TD&gt;15.01.2021 6:10:15&lt;/TD&gt;&lt;TD&gt;345876112&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;321&lt;/TD&gt;&lt;TD&gt;05.01.2021 8:15:00&lt;/TD&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;deal_id&lt;/TD&gt;&lt;TD&gt;start_date_time&lt;/TD&gt;&lt;TD&gt;end_date_time&lt;/TD&gt;&lt;TD&gt;product_id&lt;/TD&gt;&lt;TD&gt;Order_id&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;05.01.2021 8:00:00&lt;/TD&gt;&lt;TD&gt;05.01.2021 8:25:00&lt;/TD&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;05.01.2021 8:00:00&lt;/TD&gt;&lt;TD&gt;05.01.2021 8:25:00&lt;/TD&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;321&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;05.01.2021 10:00:00&lt;/TD&gt;&lt;TD&gt;05.01.2021 10:25:00&lt;/TD&gt;&lt;TD&gt;123456789&lt;/TD&gt;&lt;TD&gt;789&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any lead on this would be of great help!&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 21:10:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Output-rows-based-on-matching-date-time-intervals/m-p/1746582#M36331</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-25T21:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Output rows based on matching date time intervals</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Output-rows-based-on-matching-date-time-intervals/m-p/1749141#M36405</link>
      <description>&lt;P&gt;Do you really need second level accuracy (as in deals 321 and 654) or is minute level accuracy sufficient?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Asking because the standard answer ("Use GENERATESERIES and INTERSECT") would be much tougher to do on seconds level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an alternative approach.&amp;nbsp; In your "Modified Table A"&amp;nbsp; add a calculated column:&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;deal_id = 
var t = 'Modified Table A'[timestamp]
var p = 'Modified Table A'[product_id]
var d = CALCULATETABLE('Modified Table B','Modified Table B'[start_date_time]&amp;lt;=t,'Modified Table B'[end_date_time]&amp;gt;=t,'Modified Table B'[product_id]=p)
return CONCATENATEX(d,'Modified Table B'[deal_id],"")&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;That will give you the deal ID for any order that has a deal.&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;However, when trying to link the tables via the deal_id field you will (not surprisingly) encounter a circular reference error.&amp;nbsp; That means it would be better to implement that calculated column in Power Query instead.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc/RDYAgDEXRVUy/SewrFNFViPuvYVuCmuhfQw630DtBMiXCqquwYGkH+GD2I8lF69Z2OlMnG4OVwVANDbe3rWrJgnDuXzmLQf967t21uVZcfnI2BoMMVz0XzmImAQlnt4bT2/Gfm2uf335fd14=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [order_id = _t, timestamp = _t, product_id = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"timestamp", type datetime}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"product_id"}, #"Modified Table B", {"product_id"}, "Modified Table B", JoinKind.LeftOuter),
    #"Expanded Modified Table B" = Table.ExpandTableColumn(#"Merged Queries", "Modified Table B", {"deal_id", "start_date_time", "end_date_time"}, {"deal_id", "start_date_time", "end_date_time"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Modified Table B", "Match", each if [start_date_time]&amp;lt;=[timestamp] and [timestamp]&amp;lt;= [end_date_time] then 1 else 0),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Custom", {{"Match", 0}}),
    #"Added Custom1" = Table.AddColumn(#"Replaced Errors", "d", each if [Match]=1 then [deal_id] else null),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"order_id", "timestamp", "product_id", "d"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"d", "deal_id"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"deal_id", type text}})
in
    #"Changed Type1"&lt;/LI-CODE&gt;
&lt;P&gt;which then allows us to link the tables and produce the expected outcome&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Mar 2021 03:19:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Output-rows-based-on-matching-date-time-intervals/m-p/1749141#M36405</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-03-27T03:19:10Z</dc:date>
    </item>
  </channel>
</rss>

