<?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 Set expression within pivot table to calculate Margin % by month (Finance) in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Set-expression-within-pivot-table-to-calculate-Margin-by-month/m-p/2029343#M84795</link>
    <description>&lt;P&gt;I have a pivot table with "Actuals" figures, the rows being different categories (e.g. Total Sales, Cost of Sales, Gross Margin), the columns being Period number.&lt;/P&gt;
&lt;P&gt;Within the rows of the pivot, I also have GM1% and GM2% - GM1% being GM1/Total Sales, and so on for GM2%&lt;/P&gt;
&lt;P&gt;I use an if expression in the table measure to determine what master measure to use (if row = GM1% then use GM1% master measure, else use "Total" master measure) - this is working fine, but...&lt;/P&gt;
&lt;P&gt;My master measure for GM1%, I can't seem to figure out how to calculate the Margin % in the cell according to the corresponding period in the column.&lt;/P&gt;
&lt;P&gt;I need to calculate both Total Sales and GM1 in master measures, then create another master measure to calculate GM1% based on the previously mentioned measures.&lt;/P&gt;
&lt;P&gt;GM1 expression is:&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Sum({&amp;lt;[Total Class]={'GM1'} ,[Period reporting on] = {'=[Period reporting on]'}&amp;gt;} total Amount*-1)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Total sales expression is:&amp;nbsp;&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;S&lt;/STRONG&gt;&lt;STRONG&gt;um({&amp;lt;[Total Class]={'Total Sales'},[Period reporting on] = {'=[Period reporting on]'} &amp;gt;} total Amount*-1)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;GM1 expression is: GM1/Total Sales&lt;/P&gt;
&lt;P&gt;The problem i'm seeing is, each cell in the GM1% column is showing the same result - which is the GM1% for the whole year, not just for the corresponding month.&lt;/P&gt;
&lt;P&gt;Can anyone see what is wrong with my set expression, or should I be using a different method entirely?&lt;/P&gt;
&lt;P&gt;Please see below (bad and not very helpful) screenshot, I can't show or share any data unfortunately&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TomHollandKB_1-1674567046022.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/98728iBD0F92B2624BA859/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TomHollandKB_1-1674567046022.png" alt="TomHollandKB_1-1674567046022.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jan 2023 13:31:21 GMT</pubDate>
    <dc:creator>TomHollandKB</dc:creator>
    <dc:date>2023-01-24T13:31:21Z</dc:date>
    <item>
      <title>Set expression within pivot table to calculate Margin % by month (Finance)</title>
      <link>https://community.qlik.com/t5/App-Development/Set-expression-within-pivot-table-to-calculate-Margin-by-month/m-p/2029343#M84795</link>
      <description>&lt;P&gt;I have a pivot table with "Actuals" figures, the rows being different categories (e.g. Total Sales, Cost of Sales, Gross Margin), the columns being Period number.&lt;/P&gt;
&lt;P&gt;Within the rows of the pivot, I also have GM1% and GM2% - GM1% being GM1/Total Sales, and so on for GM2%&lt;/P&gt;
&lt;P&gt;I use an if expression in the table measure to determine what master measure to use (if row = GM1% then use GM1% master measure, else use "Total" master measure) - this is working fine, but...&lt;/P&gt;
&lt;P&gt;My master measure for GM1%, I can't seem to figure out how to calculate the Margin % in the cell according to the corresponding period in the column.&lt;/P&gt;
&lt;P&gt;I need to calculate both Total Sales and GM1 in master measures, then create another master measure to calculate GM1% based on the previously mentioned measures.&lt;/P&gt;
&lt;P&gt;GM1 expression is:&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Sum({&amp;lt;[Total Class]={'GM1'} ,[Period reporting on] = {'=[Period reporting on]'}&amp;gt;} total Amount*-1)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Total sales expression is:&amp;nbsp;&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;S&lt;/STRONG&gt;&lt;STRONG&gt;um({&amp;lt;[Total Class]={'Total Sales'},[Period reporting on] = {'=[Period reporting on]'} &amp;gt;} total Amount*-1)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;GM1 expression is: GM1/Total Sales&lt;/P&gt;
&lt;P&gt;The problem i'm seeing is, each cell in the GM1% column is showing the same result - which is the GM1% for the whole year, not just for the corresponding month.&lt;/P&gt;
&lt;P&gt;Can anyone see what is wrong with my set expression, or should I be using a different method entirely?&lt;/P&gt;
&lt;P&gt;Please see below (bad and not very helpful) screenshot, I can't show or share any data unfortunately&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TomHollandKB_1-1674567046022.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/98728iBD0F92B2624BA859/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TomHollandKB_1-1674567046022.png" alt="TomHollandKB_1-1674567046022.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 13:31:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Set-expression-within-pivot-table-to-calculate-Margin-by-month/m-p/2029343#M84795</guid>
      <dc:creator>TomHollandKB</dc:creator>
      <dc:date>2023-01-24T13:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Set expression within pivot table to calculate Margin % by month (Finance)</title>
      <link>https://community.qlik.com/t5/App-Development/Set-expression-within-pivot-table-to-calculate-Margin-by-month/m-p/2029420#M84800</link>
      <description>&lt;P&gt;I have found a workaround, although i'm sure there must be a more simple approach, I've used a pick expression to determine the GM% by month:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;if(match([Total Class],'GM1%'),&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;num(&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;pick([Period reporting on],&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;[Actual GM1% P&amp;amp;L JAN],&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;[Actual GM1% P&amp;amp;L FEB],&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;[Actual GM1% P&amp;amp;L MAR],&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;[Actual GM1% P&amp;amp;L APR],&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;[Actual GM1% P&amp;amp;L MAY],&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;[Actual GM1% P&amp;amp;L JUN]&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;,'#0.00%'),&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;num(sum(Amount)*-1,vMoneyFormat)&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Expression to calculate GM1 for January (named [Actual GM1 (P&amp;amp;L) JAN]):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;Sum({&amp;lt;[Total Class]={'GM1'},[Period reporting on] = {'1'} &amp;gt;}total Amount*-1)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Expression to calculate Total sales for January (named [Actual Total Sales P&amp;amp;L JAN]):&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;S&lt;/EM&gt;&lt;EM&gt;um({&amp;lt;[Total Class]={'Total Sales'},[Period reporting on] = {'1'} &amp;gt;} total Amount*-1)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Expression to calculate GM1% for January:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;[Actual GM1 (P&amp;amp;L) JAN]/[Actual Total Sales P&amp;amp;L JAN]&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Obviously I still have the rest of the year to fill in, in the pick expression above, but it's working a treat, just a bit of a long-winded way of doing it, as i'll need to do the same for GM2 and GM2% measures.&lt;/P&gt;
&lt;P&gt;However, fortunately I can re-use the "Total Sales" measures to calculate GM2%.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 15:18:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Set-expression-within-pivot-table-to-calculate-Margin-by-month/m-p/2029420#M84800</guid>
      <dc:creator>TomHollandKB</dc:creator>
      <dc:date>2023-01-24T15:18:56Z</dc:date>
    </item>
  </channel>
</rss>

