<?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 Not able to sum by category in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2064867#M46646</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am trying to make in one column the lower of the following:&lt;/P&gt;&lt;P&gt;([column A] / [column B] * .6) – [column A] or 0&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if the result of the calculation is negative I want that amount. If the result is positive the result should show zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently, I have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;balance:=sum(tablename [column A])

LTV:=sum(tablename [column B])

Measure 1:=sumx(tablename,([balance]/[LTV])*.6)-sum(tablename [column A])

Measure 2:=min(sumx(tablename,[Measure 1]),0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Measure 2 works on a line by line i.e. per product. But when I group this by region or colour each region/colour shows 0. For each region I want to add all the outcomes per line where the outcome is lower than 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Why is this my DAX code not working as intended, please?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Nav&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Sep 2021 17:00:21 GMT</pubDate>
    <dc:creator>naveen73</dc:creator>
    <dc:date>2021-09-08T17:00:21Z</dc:date>
    <item>
      <title>Not able to sum by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2064867#M46646</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am trying to make in one column the lower of the following:&lt;/P&gt;&lt;P&gt;([column A] / [column B] * .6) – [column A] or 0&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if the result of the calculation is negative I want that amount. If the result is positive the result should show zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently, I have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;balance:=sum(tablename [column A])

LTV:=sum(tablename [column B])

Measure 1:=sumx(tablename,([balance]/[LTV])*.6)-sum(tablename [column A])

Measure 2:=min(sumx(tablename,[Measure 1]),0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Measure 2 works on a line by line i.e. per product. But when I group this by region or colour each region/colour shows 0. For each region I want to add all the outcomes per line where the outcome is lower than 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Why is this my DAX code not working as intended, please?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Nav&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 17:00:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2064867#M46646</guid>
      <dc:creator>naveen73</dc:creator>
      <dc:date>2021-09-08T17:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to sum by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2065059#M46658</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Measure 1 = CALCULATE( ([balance] / [LTV] * 0.6 - [balance]))&lt;/P&gt;&lt;P&gt;Measure 2 = IF( [Measure 1] &amp;gt; 0, 0, [Measure 1])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 19:51:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2065059#M46658</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-08T19:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to sum by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2065725#M46675</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6957" data-lia-user-login="naveen73" class="lia-mention lia-mention-user"&gt;naveen73&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this code to add a new column and use that to cover your request:&lt;/P&gt;&lt;P&gt;New Column =&amp;nbsp;&lt;BR /&gt;Var _balance=sum(tablename [column A])&lt;BR /&gt;Var _LTV=sum(tablename [column B])&lt;BR /&gt;Var _Calc = _balance/_LTV*0.6-_balance&lt;BR /&gt;Return&lt;BR /&gt;IF(_Calc&amp;gt;=0,0,_Calc)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;SPAN&gt;, please consider &lt;STRONG&gt;accepting&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;it as the solution&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;to help the other members find it more quickly.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="helvetica"&gt;&lt;SPAN&gt;&lt;STRONG&gt;Appreciate your Kudos&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;span class="lia-unicode-emoji" title=":victory_hand:"&gt;✌️&lt;/span&gt;&lt;STRONG&gt;!!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Sep 2021 05:26:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2065725#M46675</guid>
      <dc:creator>VahidDM</dc:creator>
      <dc:date>2021-09-09T05:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to sum by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2066963#M46716</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much for your efforts. I really appreciate it. However, it does not get me the desired result. I thought I make it a bit more clear with demo data.&lt;/P&gt;&lt;P&gt;Let's start with he demo dataset is on the left and while the number do not make much sense I am of course after the DAX code &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See the results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;In the first block (upper left) we calculate the result of the following in Excel:&lt;/P&gt;&lt;P&gt;=(($C2/$D2)*(1-H$1)-$C2*1.6)&lt;/P&gt;&lt;P&gt;in words&lt;/P&gt;&lt;P&gt;((Price / discount) times (1 minus variable)) minus (Price times 1.6)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the second block (upper right) I calculate&lt;/P&gt;&lt;P&gt;=MIN(H2,0)&lt;/P&gt;&lt;P&gt;the lowest of zero and the result in the first block&lt;/P&gt;&lt;P&gt;In the pivot tables under each block the results are displayed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In one DAX Column I want achieve what can be seen in the third table i.e. per colour only when the results is below zero&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;20%&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;30%&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;40%&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;red&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;-&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;-1.22&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;- 16.52&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Blue&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;-&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;-&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;- 11.68&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Green&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;-&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;- 8.57&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;- 24.26&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or as in the pivot table below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The results I getting from the two suggestions above are in the image below. Please note that I am only taking&amp;nbsp; the last outcome i.e. what should be Sum of 40%.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Nav&lt;/P&gt;</description>
      <pubDate>Thu, 09 Sep 2021 14:15:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2066963#M46716</guid>
      <dc:creator>naveen73</dc:creator>
      <dc:date>2021-09-09T14:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to sum by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2067542#M46744</link>
      <description>&lt;P&gt;If I got it right now, you have to create 3 Measures.&lt;/P&gt;&lt;P&gt;One for 20%, one for 30% and one for 40%&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;20 % = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var calc = CALCULATE(((SUM('Sample'[Price]) / SUM('Sample'[Discount])) * (1 - 0.2)) - (SUM('Sample'[Price]) * 1.6))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;IF(calc &amp;gt; 0, "-", calc)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;30 % = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var calc = CALCULATE(((SUM('Sample'[Price]) / SUM('Sample'[Discount])) * (1 - 0.3)) - (SUM('Sample'[Price]) * 1.6))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;IF(calc &amp;gt; 0, "-", calc)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;40 % = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var calc = CALCULATE(((SUM('Sample'[Price]) / SUM('Sample'[Discount])) * (1 - 0.4)) - (SUM('Sample'[Price]) * 1.6))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;IF(calc &amp;gt; 0, "-", calc)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Then insert all the measures in the table.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;With this measures, I get the same table as above:&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;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Sep 2021 19:41:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2067542#M46744</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-09-09T19:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to sum by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2068095#M46758</link>
      <description>&lt;P&gt;From my point of view, the measure is not working as intended as first of all all columns for price are added, same for discount and then your logic is applied. You want it the other way around. First apply your logic to all single rows, then sum.&lt;BR /&gt;&lt;BR /&gt;I just recreated your data by manually entering them:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Next, because I am a huge fan of user interaction and the values of your parameter might change, create a table containing all values of your parameter, your case 0.2, 0.3, 0.4:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Next, write a measure to store the selection of the value, also asserting a standard value:&lt;BR /&gt;&lt;BR /&gt;Parameter_value = SELECTEDVALUE(Parameter[value], 0.2) (in case nothing is choosen, 0.2 is returned, assuring a calculation)&lt;BR /&gt;&lt;BR /&gt;Next, write a measure to calculate your logic, first calculating your formula on every row, summing afterwards, SUMX was made for this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Logic = SUMX(Data, IF(Data[price]/Data[discount]*(1-Parameter[Parameter_value])-1.6*Data[price] &amp;lt; 0, -(Data[price]/Data[discount]*(1-Parameter[Parameter_value])-1.6*Data[price]) , 0)) &lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;Next, visualisation:&lt;BR /&gt;&lt;BR /&gt;Use matrix value, putting a color-product hierarchy in the rows, using Logic as a value, putting column value of Parameter in the filters to switch the parameter, done! 3 screenshots for a all 3 values of your parameter:&lt;BR /&gt;&lt;BR /&gt;0.2:&lt;BR /&gt;&lt;BR /&gt;&lt;img /&gt;&lt;P&gt;0.3:&lt;/P&gt;&lt;img /&gt;&lt;P&gt;&lt;BR /&gt;0.4:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;img /&gt;&lt;P&gt;&lt;BR /&gt;Itmis easy to add new values for the parameter to the table.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Sep 2021 04:43:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2068095#M46758</guid>
      <dc:creator>Schmidtmayer</dc:creator>
      <dc:date>2021-09-10T04:43:37Z</dc:date>
    </item>
    <item>
      <title>Re: Not able to sum by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2072462#M46899</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="215136" data-lia-user-login="Schmidtmayer" class="lia-mention lia-mention-user"&gt;Schmidtmayer&lt;/a&gt;&amp;nbsp;Thanks for your time and efforts&lt;/P&gt;&lt;P&gt;The solution works well in Power BI Desktop. However, I am working in Excel and found that SELECTEDVALUE is not working in Excel. Is there a way I can change the formula so that it works in Excel?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Naveen&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 09:44:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Not-able-to-sum-by-category/m-p/2072462#M46899</guid>
      <dc:creator>naveen73</dc:creator>
      <dc:date>2021-09-13T09:44:51Z</dc:date>
    </item>
  </channel>
</rss>

