<?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 What is the most efficient way to retrieve rows with valid from to dates? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963171#M11350</link>
    <description>&lt;P&gt;neeMy fact table has a valid from and to date for each row.&lt;/P&gt;&lt;P&gt;The user needs to select a date from a dropdown list of dates and then see the valid facts retrospectively at that point of time.&lt;/P&gt;&lt;P&gt;The fact table has millions of rows so I want to use the most efficient way as possible.&lt;/P&gt;&lt;P&gt;Is this DAX measure the most efficient way to do it?&lt;/P&gt;&lt;P&gt;I am concerned FILTER is an iterator and tests row by row &amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for helping&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;Retrospective Facts =&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;--- get selected user date&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;VAR userdate&amp;nbsp; = SELECTEDVALUE('List of dates'[Date])&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;--- create a subset table with rows that were valid at the point of time&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;VAR facts_valid_at_point_in_time =&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;FILTER(&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;FactTable,&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;userdate &amp;gt;= FactTable[Valid from] &amp;amp;&amp;amp;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;userdate &amp;lt;= FactTable[Valid to]&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;RETURN&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;--- counts rows in the subset&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;COUNTROWS(facts_valid_at_point_in_time)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 07 Mar 2020 14:37:28 GMT</pubDate>
    <dc:creator>speedramps</dc:creator>
    <dc:date>2020-03-07T14:37:28Z</dc:date>
    <item>
      <title>What is the most efficient way to retrieve rows with valid from to dates?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963171#M11350</link>
      <description>&lt;P&gt;neeMy fact table has a valid from and to date for each row.&lt;/P&gt;&lt;P&gt;The user needs to select a date from a dropdown list of dates and then see the valid facts retrospectively at that point of time.&lt;/P&gt;&lt;P&gt;The fact table has millions of rows so I want to use the most efficient way as possible.&lt;/P&gt;&lt;P&gt;Is this DAX measure the most efficient way to do it?&lt;/P&gt;&lt;P&gt;I am concerned FILTER is an iterator and tests row by row &amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for helping&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;Retrospective Facts =&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;--- get selected user date&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;VAR userdate&amp;nbsp; = SELECTEDVALUE('List of dates'[Date])&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;--- create a subset table with rows that were valid at the point of time&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;VAR facts_valid_at_point_in_time =&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;FILTER(&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;FactTable,&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;userdate &amp;gt;= FactTable[Valid from] &amp;amp;&amp;amp;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;userdate &amp;lt;= FactTable[Valid to]&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;RETURN&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;--- counts rows in the subset&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;COUNTROWS(facts_valid_at_point_in_time)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 14:37:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963171#M11350</guid>
      <dc:creator>speedramps</dc:creator>
      <dc:date>2020-03-07T14:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: What is the most efficient way to retrieve rows with valid from to dates?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963190#M11351</link>
      <description>I think you already got best solution.&lt;BR /&gt;&lt;BR /&gt;This will work absolutely fine.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Pravin&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 07 Mar 2020 15:42:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963190#M11351</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-07T15:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: What is the most efficient way to retrieve rows with valid from to dates?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963236#M11354</link>
      <description>&lt;P&gt;I do not see any obvious way to improve what you have there.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 16:56:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963236#M11354</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-03-07T16:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: What is the most efficient way to retrieve rows with valid from to dates?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963299#M11360</link>
      <description>&lt;P&gt;Of course, this isn't THE BEST solution from the point of view of performance. Doing a FILTER on a fact table should always be avoided. Filter is OK on dimensions.&lt;BR /&gt;&lt;BR /&gt;The fastest solution is always based on RELATIONSHIPS. You should have a table that repeats any fact row (or just the fact id - if you don't have it, you'll need to create it) for all the dates between ValidFrom and ValidTo. There'll be a date column in the new table for the dates and your table with dates (the one you use for slicing) would be connected to this new table. Then, if you select a date from the date table, it'll auto-filter all the facts where the condition you have up there is true. This IS the fastest way to do this. It'll be at least one magnitude faster than the one based on FILTER.&lt;BR /&gt;&lt;BR /&gt;# Retro Facts = distinctcount( FactTable2[FactId] )&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 21:30:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963299#M11360</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-07T21:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: What is the most efficient way to retrieve rows with valid from to dates?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963308#M11362</link>
      <description>&lt;P&gt;If I am following&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;you want to generate a row for every fact row between the two dates? So if you have a table of 20M rows and the average date span is 100 days, then that would be 2 billion rows, or 2 orders of magnitude more rows than the original data set size. So you are saying that increasing the data set size by an order of magnitude of 2 and using relationships will net an order of magnitude increase in performance?&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 22:01:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963308#M11362</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-03-07T22:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: What is the most efficient way to retrieve rows with valid from to dates?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963314#M11364</link>
      <description>&lt;P&gt;OK&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="177566" data-lia-user-login="speedramps" class="lia-mention lia-mention-user"&gt;speedramps&lt;/a&gt;&amp;nbsp;, I find matters of performance pretty interesting so I ran some tests. Here is what I did.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created these 2 tables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Calendar = CALENDAR(DATE(2020,1,1),DATE(2020,12,31))

Table = 
    ADDCOLUMNS(
        GENERATESERIES(1,1000000,1),
        "From",DATE(2020,1,RANDBETWEEN(1,28)),
        "To",DATE(2020,12,RANDBETWEEN(1,28))
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data model size is 11MB.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I then created this table based upon what I think&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;was saying (I could be wrong!)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Table 2 = 
    GENERATE(
        GENERATESERIES(1,1000000,1),
        CALENDAR(DATE(2020,1,15),DATE(2020,12,15))
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now my data model grew to 326MB, or almost 30 times larger in disk/memory size.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created a relationship between Calendar and Table 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So now I created these two measures:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Retrospective Facts = 
VAR userdate  = SELECTEDVALUE('Calendar'[Date])
VAR facts_valid_at_point_in_time =
FILTER(
'Table',
userdate &amp;gt;= 'Table'[From] &amp;amp;&amp;amp;
userdate &amp;lt;= 'Table'[To]
)
RETURN
COUNTROWS(facts_valid_at_point_in_time)


Retrospective Facts 2 = COUNTROWS(RELATEDTABLE('Table 2'))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I put Calendar[Date] into a list slicer. I created a card visual and&amp;nbsp; put Retrospective Facts measure into the Card visual. I then duplicated this page and on the duplicate page I put replaced Retrospective Facts in the Card visual with Retrospective Facts 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I then turned on Performance Analyzer and analyzed the performance on each page. Screen shots are posted below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get an average of 177 for Retrospective Facts and 179 for Restrospective Facts 2. So, I agree with&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;that the relationship route is way faster than using filtering (if you have the same number of fact records). However, I'm not certain that the trade-offs are always worth it in terms of data model size and the increase in the number of fact records.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, great little experiment to run!&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;&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 would upload my PBIX but the file size is too large. I would also upload my JSON performance export files but this site does not allow json files to be uploaded apparently.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 22:47:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/What-is-the-most-efficient-way-to-retrieve-rows-with-valid-from/m-p/963314#M11364</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-03-07T22:47:07Z</dc:date>
    </item>
  </channel>
</rss>

