<?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 how to use your own table's fields to filter rows from another table? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-use-your-own-table-s-fields-to-filter-rows-from-another/m-p/2767566#M86013</link>
    <description>&lt;P&gt;I'm trying to create a column that counts rows of another table depending on a filter referencing fields in the current table.&amp;nbsp; Can this be done?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Specifics:&lt;/P&gt;&lt;P&gt;I have two tables, with shape as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;past_year (has 12 rows):&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Month&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Start&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;End&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;September 2022&lt;/TD&gt;&lt;TD&gt;Sept 1, 2022&lt;/TD&gt;&lt;TD&gt;Sept 30, 2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;August 2022&lt;/TD&gt;&lt;TD&gt;Aug 1, 2022&lt;/TD&gt;&lt;TD&gt;Aug 31, 2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;July 2022&lt;/TD&gt;&lt;TD&gt;July 1, 2022&lt;/TD&gt;&lt;TD&gt;July 31, 2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;events:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;idx&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Created (date)&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Completed (date)&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;lots of records&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a column in past_year distributing rows from &lt;EM&gt;events &lt;/EM&gt;in a cumulative way into the month bins, such that the created date is less than the start date, and the completed date is less than the completed date.&amp;nbsp; This is the DAX query that would yield the result I want:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;past_year[open_cumulative] = CALCULATE(countrows(events), events[Created] &amp;lt; past_year[startdate] &amp;amp;&amp;amp; events[Completed] &amp;lt; past_year[End])&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;This complains about "The expression contains columns from multiple tables...".&amp;nbsp;&lt;SPAN&gt;I also tried calculatetable instead of calculate in variation 1. same error.&amp;nbsp;So I tried the following:&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;countrows(filter(events, events[Created] &amp;lt; past_year[startdate] &amp;amp;&amp;amp; events[Completed] &amp;lt; past_year[End]))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Oddly, this yielded ony a single total applying to the values in the first row. I tried using RELATED to refer to the fields in the same table:&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;countrows(filter(events, events[Created] &amp;lt; RELATED(past_year[startdate]) &amp;amp;&amp;amp; events[Completed] &amp;lt; RELATED(past_year[End])))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It then complains about not being able to find a relationship to itself: "the column 'past_year[start]' doesn't exist or doesn't have a relationship to any table available in the current context."&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 14 Sep 2022 14:09:11 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-09-14T14:09:11Z</dc:date>
    <item>
      <title>how to use your own table's fields to filter rows from another table?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-use-your-own-table-s-fields-to-filter-rows-from-another/m-p/2767566#M86013</link>
      <description>&lt;P&gt;I'm trying to create a column that counts rows of another table depending on a filter referencing fields in the current table.&amp;nbsp; Can this be done?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Specifics:&lt;/P&gt;&lt;P&gt;I have two tables, with shape as follows:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;past_year (has 12 rows):&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Month&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Start&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;End&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;September 2022&lt;/TD&gt;&lt;TD&gt;Sept 1, 2022&lt;/TD&gt;&lt;TD&gt;Sept 30, 2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;August 2022&lt;/TD&gt;&lt;TD&gt;Aug 1, 2022&lt;/TD&gt;&lt;TD&gt;Aug 31, 2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;July 2022&lt;/TD&gt;&lt;TD&gt;July 1, 2022&lt;/TD&gt;&lt;TD&gt;July 31, 2022&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;events:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;idx&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Created (date)&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Completed (date)&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;lots of records&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a column in past_year distributing rows from &lt;EM&gt;events &lt;/EM&gt;in a cumulative way into the month bins, such that the created date is less than the start date, and the completed date is less than the completed date.&amp;nbsp; This is the DAX query that would yield the result I want:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;past_year[open_cumulative] = CALCULATE(countrows(events), events[Created] &amp;lt; past_year[startdate] &amp;amp;&amp;amp; events[Completed] &amp;lt; past_year[End])&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;This complains about "The expression contains columns from multiple tables...".&amp;nbsp;&lt;SPAN&gt;I also tried calculatetable instead of calculate in variation 1. same error.&amp;nbsp;So I tried the following:&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;countrows(filter(events, events[Created] &amp;lt; past_year[startdate] &amp;amp;&amp;amp; events[Completed] &amp;lt; past_year[End]))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Oddly, this yielded ony a single total applying to the values in the first row. I tried using RELATED to refer to the fields in the same table:&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;countrows(filter(events, events[Created] &amp;lt; RELATED(past_year[startdate]) &amp;amp;&amp;amp; events[Completed] &amp;lt; RELATED(past_year[End])))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It then complains about not being able to find a relationship to itself: "the column 'past_year[start]' doesn't exist or doesn't have a relationship to any table available in the current context."&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 14 Sep 2022 14:09:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-use-your-own-table-s-fields-to-filter-rows-from-another/m-p/2767566#M86013</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-09-14T14:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to use your own table's fields to filter rows from another table?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-use-your-own-table-s-fields-to-filter-rows-from-another/m-p/2769211#M86122</link>
      <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;HI&amp;nbsp;Anonymous&lt;/LI-USER&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;It seems like a common date range calculation requirement, you can refer to the following blog 'start date', 'end date' part or try to create a table to expand detailed date records for further calculations:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882" target="_self"&gt;Before You Post, Read This&lt;/A&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;A href="https://community.powerbi.com/t5/Desktop/Spread-revenue-across-period-based-on-start-and-end-date-slice/td-p/357648" target="_blank"&gt;Solved: Spread revenue across period based on start and en... - Microsoft Power BI Community&lt;/A&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 06:37:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-use-your-own-table-s-fields-to-filter-rows-from-another/m-p/2769211#M86122</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-09-15T06:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to use your own table's fields to filter rows from another table?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-use-your-own-table-s-fields-to-filter-rows-from-another/m-p/2780566#M86991</link>
      <description>&lt;P&gt;I think I understand - you're saying that the way to get around it is to expand my past_year table to have a row for every day in the past year, and replace my comparison operator filters with table relationships, then use the inherent rollup features to deliver the counting.&lt;BR /&gt;&lt;BR /&gt;I don't yet see how to do it that way for my need, though.&amp;nbsp; I want a cumulative total based on two fields. For example, if an event has created = April 23, 2022 and Completed = Aug 5, 2022, I want that record to add to the displayed count of only April, May, June, July, and August of 2022.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 11:55:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-use-your-own-table-s-fields-to-filter-rows-from-another/m-p/2780566#M86991</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-09-20T11:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to use your own table's fields to filter rows from another table?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-use-your-own-table-s-fields-to-filter-rows-from-another/m-p/2781012#M87010</link>
      <description>&lt;P&gt;I took another look at your "Read this first" link and actually found &lt;A href="https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364" target="_self"&gt;something&lt;/A&gt; that seemed to perfectly meet my use case. However...it's not working as advertised.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my modified measure code:&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;Tickets Open = 
VAR tmpTickets = ADDCOLUMNS('events',"Closed",if(events[Status] &amp;lt;&amp;gt; "Closed", TODAY(),[Modified]))
VAR tmpTable =  
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpTickets,
            pastyear
        ),
        [Date] &amp;gt;= events[Created] &amp;amp;&amp;amp;
        [Date] &amp;lt;= [Closed]

    ),
    "ID",'events'[ID],
    "Date",[Date]
)
VAR tmpTable1 = GROUPBY(tmpTable,[ID],"Count",COUNTX(CURRENTGROUP(),[Date]))
RETURN COUNTROWS(tmpTable1)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result:&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;Here's the source data table, with a replicated tmpTickets column matching the above logic added for easy reference:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The Sept rollup is correct, but&amp;nbsp;the Aug rollup should be 27, and all the dailies are wrong except the first.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 14:19:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/how-to-use-your-own-table-s-fields-to-filter-rows-from-another/m-p/2781012#M87010</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-09-20T14:19:35Z</dc:date>
    </item>
  </channel>
</rss>

