<?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 field parameter inside a measure in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/using-field-parameter-inside-a-measure/m-p/3775271#M147534</link>
    <description>&lt;P&gt;Thanks a lot for providing the pbix file. It does indeed works as needed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will look into detail about calculation groups as it seems I can use them in other scenarios.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a good day Sir!&lt;/P&gt;</description>
    <pubDate>Tue, 19 Mar 2024 12:27:26 GMT</pubDate>
    <dc:creator>Maneko</dc:creator>
    <dc:date>2024-03-19T12:27:26Z</dc:date>
    <item>
      <title>using field parameter inside a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/using-field-parameter-inside-a-measure/m-p/3772781#M147426</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;It is possible to use a field parameter inside a measure?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a report where I display in a line chart different moving averages for one specific column (DJM).&lt;/P&gt;&lt;P&gt;Each line is drawn using a measure (5 in total), and the users can select which line(s) to show using a slicer.&lt;/P&gt;&lt;P&gt;I also allow the users to specify how many periods they want to use for a moving average. To do so I used a numeric parameter that I include in one of the measures (SMA #) like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SMA (# weeks) =&lt;/SPAN&gt; &lt;SPAN&gt;AVERAGEX&lt;/SPAN&gt;&lt;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lt;DIV&gt;This report works perfectly for just one data column (DJM), but if I want display the same line chart for a different data column I must create another 5 measures for that new/different data column. The problem is that I have around 20 columns and I do not wish to create 100 measures...&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I tried to use the field parameter the same way I have used the numeric parameter, trying to replace in the measures&amp;nbsp;&lt;STRONG&gt;Carro[DJM]&amp;nbsp;&lt;/STRONG&gt;for &lt;STRONG&gt;prmField[prmField Opt], &lt;/STRONG&gt;but if&amp;nbsp;&lt;SPAN&gt;I click to display this line/measure, the chart &lt;/SPAN&gt;shows a display error (&lt;EM&gt;SUM does not admit strings&lt;/EM&gt;).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;SMA (&lt;/SPAN&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;SPAN&gt; weeks) =&lt;/SPAN&gt; &lt;SPAN&gt;AVERAGEX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;DATESBETWEEN&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Carro&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Carro&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt;) - (&lt;/SPAN&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;)*&lt;/SPAN&gt;&lt;SPAN&gt;7&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Carro&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt;)),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;SUM&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;prmField&lt;/SPAN&gt;&lt;SPAN&gt;[prmField Opt]&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;PS: I could no tfind how to upload here my pbix file.&amp;nbsp; Please use this link or check the pictures below:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="https://we.tl/t-mFnePxOlwp" target="_blank"&gt;https://we.tl/t-mFnePxOlwp&lt;/A&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;img /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;img /&gt;&lt;img /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks a lot for any help you might provide!&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 19 Mar 2024 00:23:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/using-field-parameter-inside-a-measure/m-p/3772781#M147426</guid>
      <dc:creator>Maneko</dc:creator>
      <dc:date>2024-03-19T00:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: using field parameter inside a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/using-field-parameter-inside-a-measure/m-p/3774349#M147501</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="706905" data-lia-user-login="Maneko" class="lia-mention lia-mention-user"&gt;Maneko&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Field parameters cannot be used within a DAX expression to create a "dynamic" reference to the underlying field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However there are different methods to get the result you want.&lt;/P&gt;
&lt;P&gt;I would suggest:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use measures instead of columns within your &lt;STRONG&gt;prmField&lt;/STRONG&gt; field parameter.&lt;/LI&gt;
&lt;LI&gt;Create a calculation group with a single calculation item to handle the moving average.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The field parameter then allows selection of which measure(s) to visualize (i.e. which column to sum) and the calculation group applies the moving average calculation to the selected measure(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attached is my attempt using your PBIX.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Created measures to SUM each column:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;DJM Sum = 
SUM ( Carro[DJM] )

GOL Sum = 
SUM ( Carro[GOL] )

// etc.&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Updated the field parameter to reference these measures:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;-------------------------------
-- Calculated Table: 'prmField'
-------------------------------
TABLE prmField = 
    {
        ("DJM", NAMEOF([DJM Sum]), 0),
        ("GOL", NAMEOF([GOL Sum]), 1),
        ("IBI", NAMEOF([IBI Sum]), 2),
        ("LHB", NAMEOF([LHB Sum]), 3),
        ("SAO", NAMEOF([SAO Sum]), 4),
        ("SCA", NAMEOF([SCA Sum]), 5)
    }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Created this calculation group:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;--------------------------------------
-- Calculation Group: 'Moving Average'
--------------------------------------
CALCULATIONGROUP 'Moving Average'[Moving Average Option]

    CALCULATIONITEM "SMA (# weeks)" = 
        VAR MaxDate = MAX ( Carro[Date] )
        RETURN
            AVERAGEX (
                DATESBETWEEN (
                    Carro[Date],
                    MaxDate - ( [prmMA_value] - 1 ) * 7,
                    MaxDate
                ),
                SELECTEDMEASURE ( )
            )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. Then assemble the chart with the field parameter on Y-axis and the calculation item applied as a visual-level filter:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Hopefully this helps even if it needs to be tweaked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Owen &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;P.S. Only super users can directly attach files to posts, so you have to use cloud storage or similar (as you have already).&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 09:08:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/using-field-parameter-inside-a-measure/m-p/3774349#M147501</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2024-03-19T09:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: using field parameter inside a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/using-field-parameter-inside-a-measure/m-p/3774363#M147502</link>
      <description>&lt;P&gt;to use the same measure for all the colums, you need to unpivot all the colums and then the category column to can be used as slicer for different column.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 09:10:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/using-field-parameter-inside-a-measure/m-p/3774363#M147502</guid>
      <dc:creator>Rupak_bi</dc:creator>
      <dc:date>2024-03-19T09:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: using field parameter inside a measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/using-field-parameter-inside-a-measure/m-p/3775271#M147534</link>
      <description>&lt;P&gt;Thanks a lot for providing the pbix file. It does indeed works as needed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will look into detail about calculation groups as it seems I can use them in other scenarios.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a good day Sir!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 12:27:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/using-field-parameter-inside-a-measure/m-p/3775271#M147534</guid>
      <dc:creator>Maneko</dc:creator>
      <dc:date>2024-03-19T12:27:26Z</dc:date>
    </item>
  </channel>
</rss>

