<?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: Using a virtual table to filter another table in SUMX function in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1580022#M31565</link>
    <description>&lt;P&gt;Here are the important measures...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Revenue In Stock Only = 
    VAR InventoryBalanceByDate =
        ADDCOLUMNS(
            ADDCOLUMNS(
                CROSSJOIN(
                    VALUES(Products[ProductId]),
			        VALUES('Calendar'[Date])
                ),
                "InventoryOnHand",
                [Inventory On Hand],
                "LastDateWithInventory",
                LASTNONBLANK(
                    FILTER(
                        ALL('Calendar'[Date]),
                        'Calendar'[Date] &amp;lt;= EARLIER('Calendar'[Date])
                    ),
                    [Inventory On Hand]
                )
            ),
            "AdjustedInventoryBalance",
            CALCULATE(
                [Inventory On Hand],
                FILTER(
                    ALL('Calendar'),
                    'Calendar'[Date] = [LastDateWithInventory]
                )
            )
        )
    RETURN
				
    IF(
        ISFILTERED('Calendar'[Date]),
        CALCULATE(
            [Total Revenue],
            FILTER(
                InventoryBalanceByDate,
                'Calendar'[Date] = MAX('Calendar'[Date]) &amp;amp;&amp;amp;
                [AdjustedInventoryBalance] &amp;lt;&amp;gt; 0
            )
        ),
        CALCULATE(
            [Total Revenue],
            FILTER(
                InventoryBalanceByDate,
                [AdjustedInventoryBalance] &amp;lt;&amp;gt; 0
            )
        )
    )

Revenue Out of Stock Only = 
    VAR InventoryBalanceByDate =
        ADDCOLUMNS(
            ADDCOLUMNS(
                CROSSJOIN(
                    VALUES(Products[ProductId]),
			        VALUES('Calendar'[Date])
                ),
                "InventoryOnHand",
                [Inventory On Hand],
                "LastDateWithInventory",
                LASTNONBLANK(
                    FILTER(
                        ALL('Calendar'[Date]),
                        'Calendar'[Date] &amp;lt;= EARLIER('Calendar'[Date])
                    ),
                    [Inventory On Hand]
                )
            ),
            "AdjustedInventoryBalance",
            CALCULATE(
                [Inventory On Hand],
                FILTER(
                    ALL('Calendar'),
                    'Calendar'[Date] = [LastDateWithInventory]
                )
            )
        )
    RETURN
				
    IF(
        ISFILTERED('Calendar'[Date]),
        CALCULATE(
            [Total Revenue],
            FILTER(
                InventoryBalanceByDate,
                'Calendar'[Date] = MAX('Calendar'[Date]) &amp;amp;&amp;amp;
                OR(
                    [AdjustedInventoryBalance] = 0,
                    ISBLANK([AdjustedInventoryBalance])
                )
            )
        ),
        CALCULATE(
            [Total Revenue],
            FILTER(
                InventoryBalanceByDate,
                OR(
                    [AdjustedInventoryBalance] = 0,
                    ISBLANK([AdjustedInventoryBalance])
                )
            )
        )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What we're doing is building a table variable that represents all dates and products, the original inventory balance for that date/product, the last date that date/product had inventory, and then creating an "adjusted balance" equal to the last time there was a record for inventory for that date/product.&amp;nbsp; That ends up looking like this.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From there we're calculating total revenue and filtering for where that adjusted balance &amp;lt;&amp;gt; 0 (for in stock items) or either is blank or equal to zero (out of stock).&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For report details, also filtered for that specific date&lt;/LI&gt;&lt;LI&gt;For report total, not filtered for dates&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Jan 2021 17:15:00 GMT</pubDate>
    <dc:creator>littlemojopuppy</dc:creator>
    <dc:date>2021-01-04T17:15:00Z</dc:date>
    <item>
      <title>Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1572242#M31345</link>
      <description>&lt;P&gt;Hello dears,&lt;/P&gt;&lt;P&gt;I have a sales table with fields:&lt;/P&gt;&lt;P&gt;* Date&lt;/P&gt;&lt;P&gt;* ProductID&lt;/P&gt;&lt;P&gt;* Revenue&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and a Stocks table with fields:&lt;/P&gt;&lt;P&gt;* Stock Date&lt;/P&gt;&lt;P&gt;* ProductID&lt;/P&gt;&lt;P&gt;* InStock_Quantity&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to calculate year revenue of products that in stock by day, for example,&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Revenue In Stock&lt;/TD&gt;&lt;TD&gt;Revenue Out of Stock&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12/01/2020&lt;/TD&gt;&lt;TD&gt;0.7M&lt;/TD&gt;&lt;TD&gt;0.3M&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12/02/2020&lt;/TD&gt;&lt;TD&gt;0.69M&lt;/TD&gt;&lt;TD&gt;0.31M&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12/03/2020&lt;/TD&gt;&lt;TD&gt;0.8M&lt;/TD&gt;&lt;TD&gt;0.2M&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i.e. the total revenue of 2020 year is 1M, on 1st Dec we had some products that made 0.7M in our yearly revenue. We had another set of products on the 2th Dec that made 0.69M in our yearly revenue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a virtual table to get stocks by products by day&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var TabStock = 
SUMMARIZE(
    Stocks,
    Stocks[ProductId],
    "Stock_QTY",
    MAXX(
        Filter(Stocks,
        Stocks[Stock Date] = MAXX(
                        FILTER(
                            Stocks,
                            Stocks[Stock Date] &amp;lt;= max('Date'[Date])
                            ),
                        [Stock Date]
                        )
                ), 
        Stocks[Max In Stock])
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I would like to filter the Sales table by products that are in stock using the above virtual&amp;nbsp; table, however I cannot write a right DAX expression for IN condition. Perhaps my issue is I must create a physical table and it's not possible to use a virtual table in the expression to filter anoter table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my result query is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;return
Calculate(
    SUMX(
        FILTER(Sales,
            Sales[ProductId] in VALUES(
                                                Filter(Allexcept(
                                                    TabStock, 
                                                    [ProductID]), 
                                                    TabStock[Stock_QTY] &amp;gt; 0
                                                )
                                                )
        ),
    Sales[Revenue]
    )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot work out with the right part of the IN section or perhaps I should use completely another approach.&lt;/P&gt;&lt;P&gt;If simplify, my measure should be like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Select
  Date,
  sum(revenue) as RevenueInStock
from Sales S
Where S.ProductID in
      (
        select distinct(S.ProductID) from Stocks S where S.Stock_Quantity &amp;gt; 0
      )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Slava&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Dec 2020 16:06:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1572242#M31345</guid>
      <dc:creator>SlavaSha7</dc:creator>
      <dc:date>2020-12-28T16:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1572318#M31349</link>
      <description>&lt;P&gt;Hi!&amp;nbsp; Try this instead...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;VAR	InventoryInStock =
	FILTER(
		ALLEXCEPT(
			TabStock, 
			[ProductID]
		), 
		TabStock[Stock_QTY] &amp;gt; 0
	)
RETURN
				
CALCULATE(
	[Total Sales],
	InventoryInStock
)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 28 Dec 2020 17:04:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1572318#M31349</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2020-12-28T17:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1573791#M31391</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="17198" data-lia-user-login="littlemojopuppy" class="lia-mention lia-mention-user"&gt;littlemojopuppy&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thank you for your reply,&lt;/P&gt;&lt;P&gt;It seams it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At least [ProductId] should be TabStock[ProductId]&lt;/P&gt;&lt;P&gt;and what is the [Total Sales] in your CALCULATE clause? Is it a measure that sum sales up?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Slava&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2020 17:20:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1573791#M31391</guid>
      <dc:creator>SlavaSha7</dc:creator>
      <dc:date>2020-12-29T17:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1573844#M31394</link>
      <description>&lt;P&gt;Is it possible to implement FILTER to the VALUES function?&lt;BR /&gt;Like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var LookupTab = Values(Stocks[ProductId), Stocks[QTY_InStock] &amp;gt; 0)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 29 Dec 2020 17:58:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1573844#M31394</guid>
      <dc:creator>SlavaSha7</dc:creator>
      <dc:date>2020-12-29T17:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1574059#M31407</link>
      <description>&lt;P&gt;I wrote some DAX that if you adapt it to your data model, it should work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[Total Sales] would be SUM([the revenue field].&amp;nbsp; And try&amp;nbsp;&lt;SPAN&gt;TabStock[ProductId] in place of where I put [Product ID]&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2020 21:39:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1574059#M31407</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2020-12-29T21:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1574061#M31408</link>
      <description>&lt;P&gt;If you can share a sample pbix I'd be happy to do this for you...&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2020 21:40:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1574061#M31408</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2020-12-29T21:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578325#M31518</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="17198" data-lia-user-login="littlemojopuppy" class="lia-mention lia-mention-user"&gt;littlemojopuppy&lt;/a&gt;&amp;nbsp;and happy New Year!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will appreciate it!&lt;/P&gt;&lt;P&gt;I attached my lab PBX file and comments, we can have a call to clarify, my skype is shamakrus&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A title="PBX file" href="https://1drv.ms/u/s!AtK7xsuZr1zsgulLtIs5kZ1NAelsdg?e=EQE0tR" target="_blank" rel="noopener"&gt;PBX file&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Slava&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 19:22:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578325#M31518</guid>
      <dc:creator>SlavaSha7</dc:creator>
      <dc:date>2021-01-03T19:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578370#M31519</link>
      <description>&lt;P&gt;Is this your homework???&amp;nbsp;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 20:36:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578370#M31519</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2021-01-03T20:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578372#M31520</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="17198" data-lia-user-login="littlemojopuppy" class="lia-mention lia-mention-user"&gt;littlemojopuppy&lt;/a&gt;&amp;nbsp;no&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have a big PBX file with ~2M rows and to simplify my queries I have created a very simple file then I am going to copy formulas to my real file.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 20:45:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578372#M31520</guid>
      <dc:creator>SlavaSha7</dc:creator>
      <dc:date>2021-01-03T20:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578373#M31521</link>
      <description>&lt;P&gt;Ok...thought I was doing something unethical&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 20:46:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578373#M31521</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2021-01-03T20:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578382#M31523</link>
      <description>&lt;P&gt;Sorry about asking if I was doing your homework...the word "lab" in the file name and the limited amount of data made me wonder.&amp;nbsp; Hope I didn't offend&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Ok...download what I did &lt;A href="https://drive.google.com/file/d/1XIjoIu-jotAZFmPxazC7OKjC1FkD9OEo/view?usp=sharing" target="_self"&gt;from here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, I changed your data model to look like this.&amp;nbsp; Calendar/Date and Products are dimensions for both Sales and Stocks.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I also created a different date table using the CALENDARAUTO() function instead of what you created in Power Query...I didn't want to screw up importing any of the other data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some measures...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total Revenue = SUM(Sales[Revenue])

Revenue In Stock Only = 
    VAR	InventoryOnHand =
        SUMMARIZE(
            'Calendar',
            'Calendar'[Date],
            "InventoryOnHand",
            [Inventory On Hand] + 0
        )
    RETURN
				
    CALCULATE(
	    [Total Revenue],
    	FILTER(
            InventoryOnHand,
            [InventoryOnHand] &amp;lt;&amp;gt; 0
        )
    )

Revenue Out of Stock Only = 
    VAR	InventoryOnHand =
        SUMMARIZE(
            'Calendar',
            'Calendar'[Date],
            "InventoryOnHand",
            [Inventory On Hand] + 0
        )
    RETURN
				
    CALCULATE(
	    [Total Revenue],
    	FILTER(
            InventoryOnHand,
            [InventoryOnHand] = 0
        )
    )

Grand Total Revenue = 
    CALCULATE(
        [Total Revenue],
        ALL('Date')
    )

Grand Total Revenue In Stock Only = 
    CALCULATE(
        [Revenue In Stock Only],
        ALL('Date')
    )

Grand Total Revenue Out of Stock Only = 
    CALCULATE(
        [Revenue Out of Stock Only],
        ALL('Date')
    )
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One question I have for you to clarify is that I'm assuming that if there is a record in Stocks for a given date and product, that means it's inventory on hand, and if not, it's inventory out of stock.&amp;nbsp; Is that true?&amp;nbsp; Reason I'm asking is that if you compare my output of 11/15 and 11/16 I get different results than your expected results posted above...&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;</description>
      <pubDate>Sun, 03 Jan 2021 21:10:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578382#M31523</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2021-01-03T21:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578400#M31527</link>
      <description>&lt;P&gt;thank you for your quick reply! I really appreciate this.&lt;/P&gt;&lt;P&gt;I understand your concern, These are my real data sets:&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;"&lt;/P&gt;&lt;P&gt;&lt;EM&gt;One question I have for you to clarify is that I'm assuming that if there is a record in Stocks for a given date and product, that means it's inventory on hand, and if not, it's inventory out of stock.&amp;nbsp; Is that true?&amp;nbsp; Reason I'm asking is that if you compare my output of 11/15 and 11/16 I get different results than your expected results posted above...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason of the difference is I assume if there is no records on the date on the Stocks table then I take the nearest value. So, for 11 / 15 we have a not zero stocks for ProductID = 1 and the next record is on 11 / 20 with zero in stock. You assume that if we have no record on the date it means zero.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To get nearest stock value on the date I use this form&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var TabOutOfStock = 
SUMMARIZE(
    Stocks,
    Stocks[ProductId],
    "Stock_QTY",
    MAXX(
        Filter(Stocks,
        Stocks[Date] = MAXX(
                        FILTER(
                            Stocks,
                            Stocks[Date] &amp;lt;= max('Date'[Date])
                            ),
                        [Date]
                        )
                ), 
        Stocks[Stocks])
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and that is why I didn't join the Stock.Date column with the Date table.&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 22:02:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578400#M31527</guid>
      <dc:creator>SlavaSha7</dc:creator>
      <dc:date>2021-01-03T22:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578403#M31528</link>
      <description>&lt;P&gt;To make sure I understand this correctly, what you're saying is that in the absence of a value on for a given date/product, you're assuming that the most recent inventory balance is still valid?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Listen...my wife starts her last semester of grad school tonight and she's already taken over the office. &amp;nbsp;Can't answer tonight but will do so tomorrow. &amp;nbsp;Fair?&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 22:17:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578403#M31528</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2021-01-03T22:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578404#M31529</link>
      <description>&lt;P&gt;By the way...those are really big PBI files. &amp;nbsp;Wondering if there might be another solution for them&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jan 2021 22:19:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578404#M31529</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2021-01-03T22:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578995#M31543</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="17198" data-lia-user-login="littlemojopuppy" class="lia-mention lia-mention-user"&gt;littlemojopuppy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;By the way...those are really big PBI files. &amp;nbsp;Wondering if there might be another solution for them&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Thank you very much for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is why I have created a test PBX file and test data to check new report&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 09:30:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1578995#M31543</guid>
      <dc:creator>SlavaSha7</dc:creator>
      <dc:date>2021-01-04T09:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1579007#M31544</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="17198" data-lia-user-login="littlemojopuppy" class="lia-mention lia-mention-user"&gt;littlemojopuppy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;To make sure I understand this correctly, what you're saying is that in the absence of a value on for a given date/product, you're assuming that the most recent inventory balance is still valid?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That's correct&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 09:41:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1579007#M31544</guid>
      <dc:creator>SlavaSha7</dc:creator>
      <dc:date>2021-01-04T09:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1579992#M31564</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="274947" data-lia-user-login="SlavaSha7" class="lia-mention lia-mention-user"&gt;SlavaSha7&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;Ok...I finally got this.&amp;nbsp; You can download &lt;A href="https://drive.google.com/file/d/1lZhYJFOL8pNpcYafMj6KPE5aPkKWmQyz/view?usp=sharing" target="_self"&gt;from here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the results...&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 17:04:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1579992#M31564</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2021-01-04T17:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1580022#M31565</link>
      <description>&lt;P&gt;Here are the important measures...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Revenue In Stock Only = 
    VAR InventoryBalanceByDate =
        ADDCOLUMNS(
            ADDCOLUMNS(
                CROSSJOIN(
                    VALUES(Products[ProductId]),
			        VALUES('Calendar'[Date])
                ),
                "InventoryOnHand",
                [Inventory On Hand],
                "LastDateWithInventory",
                LASTNONBLANK(
                    FILTER(
                        ALL('Calendar'[Date]),
                        'Calendar'[Date] &amp;lt;= EARLIER('Calendar'[Date])
                    ),
                    [Inventory On Hand]
                )
            ),
            "AdjustedInventoryBalance",
            CALCULATE(
                [Inventory On Hand],
                FILTER(
                    ALL('Calendar'),
                    'Calendar'[Date] = [LastDateWithInventory]
                )
            )
        )
    RETURN
				
    IF(
        ISFILTERED('Calendar'[Date]),
        CALCULATE(
            [Total Revenue],
            FILTER(
                InventoryBalanceByDate,
                'Calendar'[Date] = MAX('Calendar'[Date]) &amp;amp;&amp;amp;
                [AdjustedInventoryBalance] &amp;lt;&amp;gt; 0
            )
        ),
        CALCULATE(
            [Total Revenue],
            FILTER(
                InventoryBalanceByDate,
                [AdjustedInventoryBalance] &amp;lt;&amp;gt; 0
            )
        )
    )

Revenue Out of Stock Only = 
    VAR InventoryBalanceByDate =
        ADDCOLUMNS(
            ADDCOLUMNS(
                CROSSJOIN(
                    VALUES(Products[ProductId]),
			        VALUES('Calendar'[Date])
                ),
                "InventoryOnHand",
                [Inventory On Hand],
                "LastDateWithInventory",
                LASTNONBLANK(
                    FILTER(
                        ALL('Calendar'[Date]),
                        'Calendar'[Date] &amp;lt;= EARLIER('Calendar'[Date])
                    ),
                    [Inventory On Hand]
                )
            ),
            "AdjustedInventoryBalance",
            CALCULATE(
                [Inventory On Hand],
                FILTER(
                    ALL('Calendar'),
                    'Calendar'[Date] = [LastDateWithInventory]
                )
            )
        )
    RETURN
				
    IF(
        ISFILTERED('Calendar'[Date]),
        CALCULATE(
            [Total Revenue],
            FILTER(
                InventoryBalanceByDate,
                'Calendar'[Date] = MAX('Calendar'[Date]) &amp;amp;&amp;amp;
                OR(
                    [AdjustedInventoryBalance] = 0,
                    ISBLANK([AdjustedInventoryBalance])
                )
            )
        ),
        CALCULATE(
            [Total Revenue],
            FILTER(
                InventoryBalanceByDate,
                OR(
                    [AdjustedInventoryBalance] = 0,
                    ISBLANK([AdjustedInventoryBalance])
                )
            )
        )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What we're doing is building a table variable that represents all dates and products, the original inventory balance for that date/product, the last date that date/product had inventory, and then creating an "adjusted balance" equal to the last time there was a record for inventory for that date/product.&amp;nbsp; That ends up looking like this.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From there we're calculating total revenue and filtering for where that adjusted balance &amp;lt;&amp;gt; 0 (for in stock items) or either is blank or equal to zero (out of stock).&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For report details, also filtered for that specific date&lt;/LI&gt;&lt;LI&gt;For report total, not filtered for dates&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 17:15:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1580022#M31565</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2021-01-04T17:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1580026#M31566</link>
      <description>&lt;P&gt;Hope this helps!&amp;nbsp;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 17:16:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1580026#M31566</guid>
      <dc:creator>littlemojopuppy</dc:creator>
      <dc:date>2021-01-04T17:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using a virtual table to filter another table in SUMX function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1580040#M31567</link>
      <description>&lt;P&gt;Hi, thanks a lot, really appreciate your help.&lt;/P&gt;&lt;P&gt;But it seams it doesn't work. Your Grand Total Revenue In/Out of stock are the same for each day however it coudn't be correcnt due to we have different items in stock on different days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see examples&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 20:12:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-a-virtual-table-to-filter-another-table-in-SUMX-function/m-p/1580040#M31567</guid>
      <dc:creator>SlavaSha7</dc:creator>
      <dc:date>2021-01-04T20:12:30Z</dc:date>
    </item>
  </channel>
</rss>

