<?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 Add a &amp;quot;Total&amp;quot; value in a table with product categories in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-a-quot-Total-quot-value-in-a-table-with-product-categories/m-p/3324843#M124493</link>
    <description>&lt;P&gt;Dear community&lt;BR /&gt;&lt;BR /&gt;I am looking for a way to get a table with the total sales of the product categories and a "Total" row with the sum of all the total sales of each product categories (see the prefered outcome below &amp;gt; Table 1)&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Table 1: Prefered outcome&lt;BR /&gt;&lt;BR /&gt;Currently the table contains only the product categories (see the screenshot below &amp;gt; Table 2)&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Table 2: Current table&lt;BR /&gt;&lt;BR /&gt;To calculate the total I intend to create a new table with the following DAX script, which generates unfortunately not the expected outcome:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CategoriesWithTotals = 
--This script creates a table with the product categories from the Product Category
VAR _ProductCategories = 
DISTINCT(
    UNION(
        SUMMARIZE('Test Data (3)', 'Test Data (3)'[Product Category]),
        DATATABLE("Product Category", STRING, {{"Total"}} --Create a table with the data type "STRING"
        )
    )
)

VAR _TotalSum =
    SUMX('Test Data (3)',[Total])

VAR _SetTotal =
SWITCH(
    TRUE(),
    _ProductCategories &amp;lt;&amp;gt; "Total", 123,
    _ProductCategories = "Total", SUMX('Test Data (3)',[Total]),
    BLANK()
)

Return
ADDCOLUMNS(
    _ProductCategories,
    "Total", _TotalSum
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Thank you for your support.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jul 2023 09:26:08 GMT</pubDate>
    <dc:creator>MakZH</dc:creator>
    <dc:date>2023-07-11T09:26:08Z</dc:date>
    <item>
      <title>Add a "Total" value in a table with product categories</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-a-quot-Total-quot-value-in-a-table-with-product-categories/m-p/3324843#M124493</link>
      <description>&lt;P&gt;Dear community&lt;BR /&gt;&lt;BR /&gt;I am looking for a way to get a table with the total sales of the product categories and a "Total" row with the sum of all the total sales of each product categories (see the prefered outcome below &amp;gt; Table 1)&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Table 1: Prefered outcome&lt;BR /&gt;&lt;BR /&gt;Currently the table contains only the product categories (see the screenshot below &amp;gt; Table 2)&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Table 2: Current table&lt;BR /&gt;&lt;BR /&gt;To calculate the total I intend to create a new table with the following DAX script, which generates unfortunately not the expected outcome:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CategoriesWithTotals = 
--This script creates a table with the product categories from the Product Category
VAR _ProductCategories = 
DISTINCT(
    UNION(
        SUMMARIZE('Test Data (3)', 'Test Data (3)'[Product Category]),
        DATATABLE("Product Category", STRING, {{"Total"}} --Create a table with the data type "STRING"
        )
    )
)

VAR _TotalSum =
    SUMX('Test Data (3)',[Total])

VAR _SetTotal =
SWITCH(
    TRUE(),
    _ProductCategories &amp;lt;&amp;gt; "Total", 123,
    _ProductCategories = "Total", SUMX('Test Data (3)',[Total]),
    BLANK()
)

Return
ADDCOLUMNS(
    _ProductCategories,
    "Total", _TotalSum
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Thank you for your support.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 09:26:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-a-quot-Total-quot-value-in-a-table-with-product-categories/m-p/3324843#M124493</guid>
      <dc:creator>MakZH</dc:creator>
      <dc:date>2023-07-11T09:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Add a "Total" value in a table with product categories</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-a-quot-Total-quot-value-in-a-table-with-product-categories/m-p/3328429#M124664</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="490122" data-lia-user-login="MakZH" class="lia-mention lia-mention-user"&gt;MakZH&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Table2 = 
VAR _ProductCategories =
    UNION (
        SELECTCOLUMNS ( 'Table1', "Product Category", 'Table1'[Product Category] ),
        ROW ( "Product Category", "Total" )
    )
RETURN
    ADDCOLUMNS (
        _ProductCategories,
        "Sum Product Category",
        IF (
            [Product Category] = "Total",
            SUM ( 'Table1'[Sum Product Category] ),
            CALCULATE ( SUM ( 'Table1'[Sum Product Category] ), 'Table1'[Product Category] = EARLIER ( [Product Category] ) )
        )
    )&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Best Regards,&lt;BR /&gt;Gao&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;Community Support Team&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;If there is any post&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT size="3" color="#008080"&gt;&lt;EM&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt;, then please consider&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT size="3"&gt;&lt;FONT color="#008080"&gt;&lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#008080"&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT size="3"&gt;Thanks a lot!&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2" color="#FF0000"&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490" target="_blank" rel="noopener nofollow noreferrer"&gt;&lt;SPAN&gt;How to get your questions answered quickly&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;--&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216" target="_blank" rel="noopener nofollow noreferrer"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;How to provide sample data in the Power BI Forum&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2023 02:47:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-a-quot-Total-quot-value-in-a-table-with-product-categories/m-p/3328429#M124664</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-07-13T02:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Add a "Total" value in a table with product categories</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-a-quot-Total-quot-value-in-a-table-with-product-categories/m-p/3328822#M124681</link>
      <description>&lt;P&gt;Thank you Gao, this works perfectly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I also had a similar approach, first to create a calculated table with the following script&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;CategoriesWithTotals = 
--This script creates a table with the product categories from the Product Category
DISTINCT(
    UNION(
        SUMMARIZE('Test Data (3)', 'Test Data (3)'[Product Category]),
        DATATABLE("Product Category", STRING, {{"Total"}} --Create a table with the data type "STRING"
        )
    )
) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;and then create a measure for the totals&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Average Selling Price incl Total = 

Var Total =
CALCULATE(SUMX('Test Data (3)', [Total]), ALL(CategoriesWithTotals[Product Category]))

RETURN
IF (
    SELECTEDVALUE(CategoriesWithTotals[Product Category])="Total",
    Total,
    SUMX('Test Data (3)', [Total])
)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 13 Jul 2023 07:36:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Add-a-quot-Total-quot-value-in-a-table-with-product-categories/m-p/3328822#M124681</guid>
      <dc:creator>MakZH</dc:creator>
      <dc:date>2023-07-13T07:36:53Z</dc:date>
    </item>
  </channel>
</rss>

