<?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: Summarize table dynamically based on field parameter in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4385490#M174087</link>
    <description>&lt;UL&gt;&lt;LI&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="625922" data-lia-user-login="bhanu_gautam" class="lia-mention lia-mention-user"&gt;bhanu_gautam&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;but this solution doesnt work since Var Grouped table wont be treated as table and we cannot use in topn function as table.&lt;BR /&gt;Also grouping of columns needs to be dynamic , as I have many fields in the parameter ,we need to add all permuatation and combination selection manually since the slicer is multiselect&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Wed, 29 Jan 2025 05:57:35 GMT</pubDate>
    <dc:creator>as1195</dc:creator>
    <dc:date>2025-01-29T05:57:35Z</dc:date>
    <item>
      <title>Summarize table dynamically based on field parameter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4385435#M174079</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have field parameter with manufacturer,brand ,subbrand,variant fields with multiselect option&lt;BR /&gt;I want to create dax which will group sales values based on field selected and should return top 1 value.&lt;BR /&gt;I am trying to create summarize table within dax but dynamic grouping of columns based on field paramerer selection is not working .Any help in this regard would be much appreciated.&lt;BR /&gt;For example&lt;BR /&gt;If user selects manufacturer the dax should return XYZ as result&lt;BR /&gt;if user selects Manufacturer and brand then result should return Abc-a and so on&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Manufacturer&lt;/TD&gt;&lt;TD&gt;Brand&lt;/TD&gt;&lt;TD&gt;SubBrand&lt;/TD&gt;&lt;TD&gt;Variant&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Abc&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;TD&gt;a1&lt;/TD&gt;&lt;TD&gt;1000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XYZ&lt;/TD&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;ba&lt;/TD&gt;&lt;TD&gt;b1&lt;/TD&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Abc&lt;/TD&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;ab&lt;/TD&gt;&lt;TD&gt;a2&lt;/TD&gt;&lt;TD&gt;1200&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 29 Jan 2025 04:48:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4385435#M174079</guid>
      <dc:creator>as1195</dc:creator>
      <dc:date>2025-01-29T04:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize table dynamically based on field parameter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4385462#M174081</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="437676" data-lia-user-login="as1195" class="lia-mention lia-mention-user"&gt;as1195&lt;/a&gt;&amp;nbsp;, First create a field parameter and create list&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use DAX to create a measure that dynamically groups and summarizes the sales values based on the selected fields.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DynamicSummary = &lt;BR /&gt;VAR SelectedFields = VALUES('FieldParameter'[Field])&lt;BR /&gt;VAR GroupedTable = &lt;BR /&gt;SWITCH(&lt;BR /&gt;TRUE(),&lt;BR /&gt;"Manufacturer" IN SelectedFields, SUMMARIZE('SalesTable', 'SalesTable'[Manufacturer], "TotalSales", SUM('SalesTable'[sales])),&lt;BR /&gt;"Manufacturer" IN SelectedFields &amp;amp;&amp;amp; "Brand" IN SelectedFields, SUMMARIZE('SalesTable', 'SalesTable'[Manufacturer], 'SalesTable'[Brand], "TotalSales", SUM('SalesTable'[sales])),&lt;BR /&gt;"Manufacturer" IN SelectedFields &amp;amp;&amp;amp; "Brand" IN SelectedFields &amp;amp;&amp;amp; "SubBrand" IN SelectedFields, SUMMARIZE('SalesTable', 'SalesTable'[Manufacturer], 'SalesTable'[Brand], 'SalesTable'[SubBrand], "TotalSales", SUM('SalesTable'[sales])),&lt;BR /&gt;"Manufacturer" IN SelectedFields &amp;amp;&amp;amp; "Brand" IN SelectedFields &amp;amp;&amp;amp; "SubBrand" IN SelectedFields &amp;amp;&amp;amp; "Variant" IN SelectedFields, SUMMARIZE('SalesTable', 'SalesTable'[Manufacturer], 'SalesTable'[Brand], 'SalesTable'[SubBrand], 'SalesTable'[Variant], "TotalSales", SUM('SalesTable'[sales])),&lt;BR /&gt;SUMMARIZE('SalesTable', 'SalesTable'[Manufacturer], "TotalSales", SUM('SalesTable'[sales]))&lt;BR /&gt;)&lt;BR /&gt;VAR TopResult = TOPN(1, GroupedTable, [TotalSales], DESC)&lt;BR /&gt;RETURN&lt;BR /&gt;TopResult&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2025 05:23:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4385462#M174081</guid>
      <dc:creator>bhanu_gautam</dc:creator>
      <dc:date>2025-01-29T05:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize table dynamically based on field parameter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4385490#M174087</link>
      <description>&lt;UL&gt;&lt;LI&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="625922" data-lia-user-login="bhanu_gautam" class="lia-mention lia-mention-user"&gt;bhanu_gautam&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;but this solution doesnt work since Var Grouped table wont be treated as table and we cannot use in topn function as table.&lt;BR /&gt;Also grouping of columns needs to be dynamic , as I have many fields in the parameter ,we need to add all permuatation and combination selection manually since the slicer is multiselect&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 29 Jan 2025 05:57:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4385490#M174087</guid>
      <dc:creator>as1195</dc:creator>
      <dc:date>2025-01-29T05:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize table dynamically based on field parameter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4387235#M174158</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="437676" data-lia-user-login="as1195" class="lia-mention lia-mention-user"&gt;as1195&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does &lt;STRONG&gt;Manufacturer &amp;gt; Brand &amp;gt; SubBrand &amp;gt; Variant&lt;/STRONG&gt; form a "&lt;A href="https://www.sqlbi.com/articles/natural-hierarchies-in-power-pivot-and-tabular/#:~:text=can%20define%20a-,natural%20hierarchy,-by%20using%20attribute" target="_blank" rel="noopener"&gt;natural hierarchy&lt;/A&gt;"? It appears so from your sample data at least &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is, does any value at a particular level imply a unique value at the level immediately above?&lt;/P&gt;
&lt;P&gt;i.e. each Variant exists under a unique SubBrand, each SubBrand exists under a unique Brand etc?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is a natural hierarchy, I believe it is possible and I can put together an example. If it is not a natural hierarchy, you could still adjust the model to create a natural hierarchy behind the scenes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regardless, I will put together an example based on what I am thinking and reply soon. The main difficulty is that field parameters are intended to determine fields included in a visual, but not to generate dynamic DAX expressions using those fields.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2025 04:38:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4387235#M174158</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2025-01-30T04:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize table dynamically based on field parameter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4387329#M174162</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="437676" data-lia-user-login="as1195" class="lia-mention lia-mention-user"&gt;as1195&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-pm-slice="0 0 []"&gt;To solve the dynamic grouping issue in Power BI using DAX, you need a measure that adjusts based on the selected field parameter (e.g., Manufacturer, Brand, SubBrand, or Variant). The DAX formula uses SELECTEDVALUE to capture the field selected by the user. The SWITCH function is used to dynamically choose the grouping field and calculate the total sales for each group using SUMMARIZE. Then, the TOPN function returns the top 1 value based on sales in descending order, ensuring that the result reflects the highest sales group. Finally, MAXX extracts the total sales value of the top result. This measure works for any dynamic combination of fields selected, such as Manufacturer alone or Manufacturer and Brand together. It ensures the correct top value is returned based on user input, offering flexibility in grouping and analysis.&lt;/P&gt;
&lt;P data-pm-slice="0 0 []"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-pm-slice="0 0 []"&gt;Updated DAX:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Top Sales Based on Selection = 
VAR SelectedField = SELECTEDVALUE('FieldParameter'[Field]) -- get the selected field parameter value
VAR GroupedData =
    SWITCH(
        TRUE(),
        SelectedField = "Manufacturer", 
            SUMMARIZE('SalesData', 'SalesData'[Manufacturer], "TotalSales", SUM('SalesData'[Sales])),
        SelectedField = "Brand", 
            SUMMARIZE('SalesData', 'SalesData'[Brand], "TotalSales", SUM('SalesData'[Sales])),
        SelectedField = "SubBrand", 
            SUMMARIZE('SalesData', 'SalesData'[SubBrand], "TotalSales", SUM('SalesData'[Sales])),
        SelectedField = "Variant", 
            SUMMARIZE('SalesData', 'SalesData'[Variant], "TotalSales", SUM('SalesData'[Sales])),
        BLANK()
    )
VAR TopValue = 
    TOPN(1, GroupedData, [TotalSales], DESC) -- Top 1 value based on sales
RETURN
    IF(
        NOT ISBLANK(TopValue),
        MAXX(TopValue, [TotalSales]),
        BLANK()
    )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2025 05:09:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4387329#M174162</guid>
      <dc:creator>Poojara_D12</dc:creator>
      <dc:date>2025-01-30T05:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize table dynamically based on field parameter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4405985#M174926</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="437676" data-lia-user-login="as1195" class="lia-mention lia-mention-user"&gt;as1195&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure if you're still looking for a solution to this, but I have attached a PBIX showing the method I was thinking of.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is based on the sample dataset from your original post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1. Model diagram:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;2. Product table&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Product&lt;/STRONG&gt; is a typical product table with a Product Key column added.&lt;/P&gt;
&lt;P&gt;For this method to work, the assumption is that Manufacturer&amp;gt;Brand&amp;gt;SubBrand&amp;gt;Variant forms a natural hierarchy.&lt;/P&gt;
&lt;P&gt;This means that the "deepest" level of the hierarchy maps 1:1 to the combinations of values on all levels of the hierarchy.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;3. ProductAttributeValue table&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This is created by unpivoting all columns of &lt;STRONG&gt;Product&lt;/STRONG&gt; except &lt;STRONG&gt;Product Key&lt;/STRONG&gt;, and adding a &lt;STRONG&gt;Depth&lt;/STRONG&gt; column.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ProductAttributeValue[Attribute]&lt;/STRONG&gt; is related to &lt;STRONG&gt;'Product Parameter'[Product Parameter]&lt;/STRONG&gt;, so that when particular fields are selected, the visible rows of &lt;STRONG&gt;ProductAttributeValue&lt;/STRONG&gt; include those levels of the Product hierarchy.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;4. Top Attribute Combination measure&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This measure assumes you have a &lt;STRONG&gt;Sales Amount&lt;/STRONG&gt; measure, and uses the above model to return the result you were looking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Top Attribute Combination = 
VAR MaxDepthSales =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE (
                ProductAttributeValue,
                ProductAttributeValue[Value],
                ProductAttributeValue[Depth]
            ),
            "@Sales", [Sales Amount]
        ),
        LASTNONBLANK ( ProductAttributeValue[Depth], 0 ) -- Filter on max depth
    )
VAR MaxDepthTopAttribute =
    INDEX (
        1,
        MaxDepthSales,
        ORDERBY ( [@Sales], DESC, ProductAttributeValue[Value], ASC ) -- break ties lexicographically
    )
VAR MaxDepthTopAttributeProducts =
    CALCULATETABLE (
        VALUES ( ProductAttributeValue[Product Key] ),
        MaxDepthTopAttribute
    )
VAR AttributeConcatenation =
    CALCULATE (
        CONCATENATEX (
            SUMMARIZE (
                ProductAttributeValue,
                ProductAttributeValue[Value],
                ProductAttributeValue[Depth]
            ),
            ProductAttributeValue[Value],
            "-",
            ProductAttributeValue[Depth]
        ),
        MaxDepthTopAttributeProducts
    )
RETURN
    AttributeConcatenation&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;5. Report example&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;I realise this requires a little setup, but I can't see any other method of producing this result.&lt;/P&gt;
&lt;P&gt;Conditional tables or tables with conditional lineage are not possible, so there is no way to directly map the field parameter selection to column references within DAX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does something like this work for you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 02:02:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-table-dynamically-based-on-field-parameter/m-p/4405985#M174926</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2025-02-12T02:02:58Z</dc:date>
    </item>
  </channel>
</rss>

