<?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: Calculation causes &amp;quot;not enough memory&amp;quot; error in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3827703#M149652</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="647378" data-lia-user-login="Jarecki" class="lia-mention lia-mention-user"&gt;Jarecki&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the following&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Return&lt;BR /&gt;If (&lt;BR /&gt;Not isempty ( V_Order_Cost_Breakdown_Pivot_ProfitabilityRep ), __Result)&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2024 13:46:11 GMT</pubDate>
    <dc:creator>tamerj1</dc:creator>
    <dc:date>2024-04-10T13:46:11Z</dc:date>
    <item>
      <title>Calculation causes "not enough memory" error</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3824879#M149570</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I hope someone will be able to help me with performance issue.&lt;/P&gt;&lt;P&gt;I'm using PowerBI Desktop RS (May 2023) based on Tabular Model.&lt;/P&gt;&lt;P&gt;Fact table contains only 24 rows (here is just a pice of this table):&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Problematic measure looks like this:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;_test = 
VAR __Category = IF(SELECTEDVALUE(Category[Category_Group]) = "Standard Cost", 6, 12)
VAR __Total =
    CALCULATE(
        [_SumOfCol_n1]
            - [_SumOfCol_49]
            - [_SumOfCol_9]
            - [_SumOfCol_45]
            - [_SumOfCol_50]
        , V_Order_Cost_Breakdown_Pivot_ProfitabilityRep[Attribute_Nr] = __Category
        , ALL(Category)
    )
VAR __Result =
    SWITCH(
        SELECTEDVALUE(Category[Category_ShortDesc]),
        "Total", __Total,
        "1000SQM", DIVIDE(__Total, [_SumCOL_NetSqm]) * 1000,
        "1000KG", DIVIDE(__Total, [_SumCOL_OrderedWght]) * 1000,
        "1000PCS", DIVIDE(__Total, [_SumCOL_OrderedQty]) * 1000
    )
RETURN
    __Result&lt;/LI-CODE&gt;&lt;P&gt;The goal of this measure is to get Value from row where Attribute nr is 6 or 12 (depends of slicer selection) for each Order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I'm adding this measure to empty table it's working fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Problem starst when I'm adding fields from other Dimensions table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So this works fine (script generated by PowerBI Performance analyzer):&lt;/P&gt;&lt;LI-CODE lang="java"&gt;DEFINE
    MEASURE '!Measures'[_test] =
        (
            VAR __Category =
                IF ( SELECTEDVALUE ( Category[Category_Group] ) = "Standard Cost", 6, 12 )
            VAR __Total =
                CALCULATE (
                    [_SumOfCol_n1] - [_SumOfCol_49] - [_SumOfCol_9] - [_SumOfCol_45] - [_SumOfCol_50],
                    V_Order_Cost_Breakdown_Pivot_ProfitabilityRep[Attribute_Nr] = __Category,
                    ALL ( Category )
                )
            VAR __Result =
                SWITCH (
                    SELECTEDVALUE ( Category[Category_ShortDesc] ),
                    "Total", __Total,
                    "1000SQM", DIVIDE ( __Total, [_SumCOL_NetSqm] ) * 1000,
                    "1000KG", DIVIDE ( __Total, [_SumCOL_OrderedWght] ) * 1000,
                    "1000PCS", DIVIDE ( __Total, [_SumCOL_OrderedQty] ) * 1000
                )
            RETURN
                __Result 
        )
    VAR __DS0FilterTable =
        TREATAS ( { "Standard Cost" }, 'Category'[Category_Group] )
    VAR __DS0FilterTable2 =
        TREATAS ( { "1000KG" }, 'Category'[Category_ShortDesc] )
    VAR __DS0Core =
        SUMMARIZECOLUMNS (
            ROLLUPADDISSUBTOTAL (
                ROLLUPGROUP (
                    'V_Order_Cost_Breakdown_Pivot_ProfitabilityRep'[LINK_Order],
                    'V_D_Customer'[LINK_Customer]
                ),
                "IsGrandTotalRowTotal"
            ),
            __DS0FilterTable,
            __DS0FilterTable2,
            "_test", '!Measures'[_test]
        )
    VAR __DS0PrimaryWindowed =
        TOPN (
            502,
            __DS0Core,
            [IsGrandTotalRowTotal], 0,
            'V_Order_Cost_Breakdown_Pivot_ProfitabilityRep'[LINK_Order], 1,
            'V_D_Customer'[LINK_Customer], 1
        )

EVALUATE
__DS0PrimaryWindowed
ORDER BY
    [IsGrandTotalRowTotal] DESC,
    'V_Order_Cost_Breakdown_Pivot_ProfitabilityRep'[LINK_Order],
    'V_D_Customer'[LINK_Customer]&lt;/LI-CODE&gt;&lt;P&gt;And this not:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;DEFINE
    MEASURE '!Measures'[_test] =
        (
            VAR __Category =
                IF ( SELECTEDVALUE ( Category[Category_Group] ) = "Standard Cost", 6, 12 )
            VAR __Total =
                CALCULATE (
                    [_SumOfCol_n1] - [_SumOfCol_49] - [_SumOfCol_9] - [_SumOfCol_45] - [_SumOfCol_50],
                    V_Order_Cost_Breakdown_Pivot_ProfitabilityRep[Attribute_Nr] = __Category,
                    ALL ( Category )
                )
            VAR __Result =
                SWITCH (
                    SELECTEDVALUE ( Category[Category_ShortDesc] ),
                    "Total", __Total,
                    "1000SQM", DIVIDE ( __Total, [_SumCOL_NetSqm] ) * 1000,
                    "1000KG", DIVIDE ( __Total, [_SumCOL_OrderedWght] ) * 1000,
                    "1000PCS", DIVIDE ( __Total, [_SumCOL_OrderedQty] ) * 1000
                )
            RETURN
                __Result 
        )
    VAR __DS0FilterTable =
        TREATAS ( { "Standard Cost" }, 'Category'[Category_Group] )
    VAR __DS0FilterTable2 =
        TREATAS ( { "1000KG" }, 'Category'[Category_ShortDesc] )
    VAR __DS0Core =
        SUMMARIZECOLUMNS (
            ROLLUPADDISSUBTOTAL (
                ROLLUPGROUP (
                    'V_Order_Cost_Breakdown_Pivot_ProfitabilityRep'[LINK_Order],
                    'V_D_Customer'[LINK_Customer],
                    'V_D_Location'[LINK_Location]
                ),
                "IsGrandTotalRowTotal"
            ),
            __DS0FilterTable,
            __DS0FilterTable2,
            "_test", '!Measures'[_test]
        )
    VAR __DS0PrimaryWindowed =
        TOPN (
            502,
            __DS0Core,
            [IsGrandTotalRowTotal], 0,
            'V_Order_Cost_Breakdown_Pivot_ProfitabilityRep'[LINK_Order], 1,
            'V_D_Customer'[LINK_Customer], 1
        )

EVALUATE
__DS0PrimaryWindowed
ORDER BY
    [IsGrandTotalRowTotal] DESC,
    'V_Order_Cost_Breakdown_Pivot_ProfitabilityRep'[LINK_Order],
    'V_D_Customer'[LINK_Customer]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My suspection is part of measure:&amp;nbsp;ALL ( Category ), but I don't know how may I replace it&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 21:18:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3824879#M149570</guid>
      <dc:creator>Jarecki</dc:creator>
      <dc:date>2024-04-09T21:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation causes "not enough memory" error</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3824941#M149573</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="647378" data-lia-user-login="Jarecki" class="lia-mention lia-mention-user"&gt;Jarecki&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try to replace&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SELECTEDVALUE ( Category[Category_Group] )&lt;BR /&gt;by&lt;/P&gt;
&lt;P&gt;MAXX ( SUMMARIZE ( FactTable, Category[Category_Group] ),&amp;nbsp;&lt;SPAN&gt;Category[Category_Group] )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and replace&amp;nbsp;SELECTEDVALUE ( Category[Category_ShortDesc] )&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;by&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;MAXX ( SUMMARIZE ( FactTable, Category[Category_ShortDesc] ),&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Category[Category_ShortDesc] )&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2024 22:06:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3824941#M149573</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2024-04-09T22:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation causes "not enough memory" error</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3825869#M149598</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;thanks for quick reply.&lt;/P&gt;&lt;P&gt;So I made a change regarding to your suggestions, but result is the same.&lt;BR /&gt;When I'm trying to add another field from different related table I get "not enought memory" error&lt;/P&gt;&lt;LI-CODE lang="java"&gt;_test = 
VAR __Category = 
            IF(MAXX(SUMMARIZE ( V_Order_Cost_Breakdown_Pivot_ProfitabilityRep
                                , Category[Category_Group] 
                            )
                    , Category[Category_Group] 
                ) = "Standard Cost", 6, 12
            )

VAR __Total =
    CALCULATE(
        [_SumOfCol_n1]
            - [_SumOfCol_49]
            - [_SumOfCol_9]
            - [_SumOfCol_45]
            - [_SumOfCol_50]
        , V_Order_Cost_Breakdown_Pivot_ProfitabilityRep[Attribute_Nr] = __Category
        , ALL(Category)
    )
VAR __Result =
    SWITCH(
        MAXX(SUMMARIZE(V_Order_Cost_Breakdown_Pivot_ProfitabilityRep
                        , Category[Category_ShortDesc] 
            )
            , Category[Category_ShortDesc] 
        ),
        "Total", __Total,
        "1000SQM", DIVIDE(__Total, [_SumCOL_NetSqm]) * 1000,
        "1000KG", DIVIDE(__Total, [_SumCOL_OrderedWght]) * 1000,
        "1000PCS", DIVIDE(__Total, [_SumCOL_OrderedQty]) * 1000
    )
RETURN
    __Result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 07:14:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3825869#M149598</guid>
      <dc:creator>Jarecki</dc:creator>
      <dc:date>2024-04-10T07:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation causes "not enough memory" error</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3827703#M149652</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="647378" data-lia-user-login="Jarecki" class="lia-mention lia-mention-user"&gt;Jarecki&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the following&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Return&lt;BR /&gt;If (&lt;BR /&gt;Not isempty ( V_Order_Cost_Breakdown_Pivot_ProfitabilityRep ), __Result)&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 13:46:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3827703#M149652</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2024-04-10T13:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation causes "not enough memory" error</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3830057#M149747</link>
      <description>&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;I figured out different solution.&lt;/P&gt;&lt;P&gt;Instead of using [&lt;STRONG&gt;ALL (Category)&lt;/STRONG&gt;] I used [&lt;STRONG&gt;REMOVEFILTERS(Category)&lt;/STRONG&gt;] and magically performance has been fixed and now everything works as I expected.&lt;/P&gt;&lt;P&gt;Now my measure look like this:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;_test = 
    VAR __Total_STD = 
        CALCULATE([_SumOfCol_n1] - [_SumOfCol_49] - [_SumOfCol_9] - [_SumOfCol_45] - [_SumOfCol_50]
            , V_Order_Cost_Breakdown_Pivot_ProfitabilityRep[Attribute_Nr] = 6
            , REMOVEFILTERS(Category)
        )
    VAR __Total_QUO = 
        CALCULATE([_SumOfCol_n1] - [_SumOfCol_49] - [_SumOfCol_9] - [_SumOfCol_45] - [_SumOfCol_50]
            , V_Order_Cost_Breakdown_Pivot_ProfitabilityRep[Attribute_Nr] = 12
            , REMOVEFILTERS(Category)
        )
    VAR __Total = SWITCH(SELECTEDVALUE(Category[Category_Group_Nr])
                        , 1 , __Total_STD
                        , __Total_QUO
                )
    VAR __Result =
        SWITCH(SELECTEDVALUE(Category[Category_ShortDesc])
            , "Total", __Total
            , "1000SQM", DIVIDE(__Total, [_SumCOL_NetSqm]) * 1000
            , "1000KG", DIVIDE(__Total, [_SumCOL_OrderedWght]) * 1000
            , "1000PCS", DIVIDE(__Total, [_SumCOL_OrderedQty]) * 1000
        )
RETURN
    __Result&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 11 Apr 2024 08:25:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculation-causes-quot-not-enough-memory-quot-error/m-p/3830057#M149747</guid>
      <dc:creator>Jarecki</dc:creator>
      <dc:date>2024-04-11T08:25:44Z</dc:date>
    </item>
  </channel>
</rss>

