<?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 TREATAS working as a calculate filter in DAX Studio but not Power BI Desktop in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/1998622#M44366</link>
    <description>&lt;P&gt;Ok, here goes:&lt;/P&gt;&lt;P&gt;I want to create a measure in Power BI Desktop that is &lt;SPAN&gt;SUM&lt;/SPAN&gt; &lt;SPAN&gt;(&lt;/SPAN&gt; &lt;SPAN&gt;'fact Back Order Demand'[Ordered Units Backordered]&lt;/SPAN&gt; &lt;SPAN&gt;) *but* only returns a value for Items (products) with the Top N number of backordered units. The following query in DAX Studio works exactly how I want it to:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;EVALUATE
VAR Top_N =
    MAX ( 'TopN'[TopN] )
VAR filtered_items =
    SELECTCOLUMNS (
        TOPN (
            Top_N,
            SUMMARIZE (
                'fact Back Order Demand',
                'fact Back Order Demand'[OrderedItemKey],
                "OUBamt", SUM ( 'fact Back Order Demand'[Ordered Units Backordered] )
            ),
            [DUBamt]
        ),
        "OrderedItemKey", [OrderedItemKey]
    )
RETURN
    SUMMARIZECOLUMNS (
        'Item Details (Ordered Items)'[Item Description],
        "OUB",
            CALCULATE (
                SUM ( 'fact Back Order Demand'[Ordered Units Backordered] ),
                TREATAS ( filtered_items, 'fact Back Order Demand'[OrderedItemKey] )
            )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I can set Top_N = 5, and the query returns the following:&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;There's a tie, so it returns 6 records, but it's acting exactly how I want. So what's the problem? I *cannot* get the measure to function in PBI Desktop:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;It returns data for all items, not just the Top 5! As far as I can tell, TREATAS is not working to filter the CALCULATE(SUM()) but I don't know why. What am I missing? Is there any alternative solution? Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 04 Aug 2021 21:57:56 GMT</pubDate>
    <dc:creator>kthxbye</dc:creator>
    <dc:date>2021-08-04T21:57:56Z</dc:date>
    <item>
      <title>TREATAS working as a calculate filter in DAX Studio but not Power BI Desktop</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/1998622#M44366</link>
      <description>&lt;P&gt;Ok, here goes:&lt;/P&gt;&lt;P&gt;I want to create a measure in Power BI Desktop that is &lt;SPAN&gt;SUM&lt;/SPAN&gt; &lt;SPAN&gt;(&lt;/SPAN&gt; &lt;SPAN&gt;'fact Back Order Demand'[Ordered Units Backordered]&lt;/SPAN&gt; &lt;SPAN&gt;) *but* only returns a value for Items (products) with the Top N number of backordered units. The following query in DAX Studio works exactly how I want it to:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;EVALUATE
VAR Top_N =
    MAX ( 'TopN'[TopN] )
VAR filtered_items =
    SELECTCOLUMNS (
        TOPN (
            Top_N,
            SUMMARIZE (
                'fact Back Order Demand',
                'fact Back Order Demand'[OrderedItemKey],
                "OUBamt", SUM ( 'fact Back Order Demand'[Ordered Units Backordered] )
            ),
            [DUBamt]
        ),
        "OrderedItemKey", [OrderedItemKey]
    )
RETURN
    SUMMARIZECOLUMNS (
        'Item Details (Ordered Items)'[Item Description],
        "OUB",
            CALCULATE (
                SUM ( 'fact Back Order Demand'[Ordered Units Backordered] ),
                TREATAS ( filtered_items, 'fact Back Order Demand'[OrderedItemKey] )
            )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I can set Top_N = 5, and the query returns the following:&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;There's a tie, so it returns 6 records, but it's acting exactly how I want. So what's the problem? I *cannot* get the measure to function in PBI Desktop:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;It returns data for all items, not just the Top 5! As far as I can tell, TREATAS is not working to filter the CALCULATE(SUM()) but I don't know why. What am I missing? Is there any alternative solution? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Aug 2021 21:57:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/1998622#M44366</guid>
      <dc:creator>kthxbye</dc:creator>
      <dc:date>2021-08-04T21:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: TREATAS working as a calculate filter in DAX Studio but not Power BI Desktop</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/1999043#M44380</link>
      <description>&lt;P&gt;What is source table of the [Item Description] in your matrix?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 03:19:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/1999043#M44380</guid>
      <dc:creator>Mohammad_Refaei</dc:creator>
      <dc:date>2021-08-05T03:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: TREATAS working as a calculate filter in DAX Studio but not Power BI Desktop</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/1999047#M44381</link>
      <description>&lt;P&gt;because with the filter context, each row only have one item.&lt;/P&gt;
&lt;P&gt;try to change the code of&amp;nbsp;filtered_items&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR filtered_items =
    SELECTCOLUMNS (
        TOPN (
            Top_N,
            SUMMARIZE (
                ALLSELECTED('fact Back Order Demand'),
                'fact Back Order Demand'[OrderedItemKey],
                "OUBamt", SUM ( 'fact Back Order Demand'[Ordered Units Backordered] )
            ),
            [DUBamt]
        ),
        "OrderedItemKey", [OrderedItemKey]
    )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 03:22:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/1999047#M44381</guid>
      <dc:creator>wdx223_Daniel</dc:creator>
      <dc:date>2021-08-05T03:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: TREATAS working as a calculate filter in DAX Studio but not Power BI Desktop</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/2000707#M44414</link>
      <description>&lt;P&gt;I see what you're saying.... however, adding an ALLSELECTED() to the 'fact Back Order Demand' table did not resolve the issue. The measure in Power BI is still returning a value for all items, not just the Top N. I will look at other ways to adjust the filter context for filtered_items.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 16:45:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/2000707#M44414</guid>
      <dc:creator>kthxbye</dc:creator>
      <dc:date>2021-08-05T16:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: TREATAS working as a calculate filter in DAX Studio but not Power BI Desktop</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/2000708#M44415</link>
      <description>&lt;P&gt;&lt;SPAN&gt;'Item Details (Ordered Items)'[Item Description]&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 16:46:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/2000708#M44415</guid>
      <dc:creator>kthxbye</dc:creator>
      <dc:date>2021-08-05T16:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: TREATAS working as a calculate filter in DAX Studio but not Power BI Desktop</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/2000835#M44420</link>
      <description>&lt;P&gt;I feel like there's something here with an iterator function, perhaps a SUMX()?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 18:13:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/2000835#M44420</guid>
      <dc:creator>kthxbye</dc:creator>
      <dc:date>2021-08-05T18:13:29Z</dc:date>
    </item>
    <item>
      <title>Re: TREATAS working as a calculate filter in DAX Studio but not Power BI Desktop</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/2000982#M44428</link>
      <description>&lt;P&gt;You're definitely right, there's a problem with the filtered_items filter context:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;In this case, when I just want to count the number of items being returned, it's showing the correct number for the Total (5) and then seemingly ignoring the Top_N filter for the rest and returning the total number of items (87).&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2021 20:19:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/2000982#M44428</guid>
      <dc:creator>kthxbye</dc:creator>
      <dc:date>2021-08-05T20:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: TREATAS working as a calculate filter in DAX Studio but not Power BI Desktop</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/2001127#M44435</link>
      <description>&lt;LI-CODE lang="markup"&gt;Demand Units Backordered = 
        CALCULATE (
            SUM ( 'fact Back Order Demand'[Ordered Units Backordered] ),
            TREATAS (
                SELECTCOLUMNS (
                    TOPN (
                        5,
                        SUMMARIZE (
                            ALLSELECTED ( 'bridge Build of Materials' ),
                            'bridge Build of Materials'[OrderedItemKey],
                            "OUB", SUM ( 'fact Back Order Demand'[Ordered Units Backordered] )
                        ),
                        [OUB]
                    ),
                    "OrderedItemKey", [OrderedItemKey]
                ),
                'fact Back Order Demand'[OrderedItemKey]
            )
        )&lt;/LI-CODE&gt;&lt;P&gt;I finally got there in the end ... this measure works, and it's performance isn't too slow.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 00:28:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TREATAS-working-as-a-calculate-filter-in-DAX-Studio-but-not/m-p/2001127#M44435</guid>
      <dc:creator>kthxbye</dc:creator>
      <dc:date>2021-08-06T00:28:45Z</dc:date>
    </item>
  </channel>
</rss>

