<?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 Calculate amounts by order in Quick Measures Gallery</title>
    <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Calculate-amounts-by-order/m-p/684847#M341</link>
    <description>&lt;P&gt;This come up from a post on the community, were it was needed to calculate the total price for orders based on a quantity / price table were the order of the table was by price:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="width: 95px;"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;Amount&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;Price&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;100&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€1,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;300&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€2,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;50&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€3,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;500&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€4,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;8000&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€5,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;900&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€6,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;2700&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€7,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;4700&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€8,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;6000&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€9,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The idea was if someone asked for 2000 units the order was fulfilled based on the lowest price until reaching the 2000 units so would be something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;100 stock for&amp;nbsp; &amp;nbsp; 1 € =&amp;nbsp; &amp;nbsp;100 €&lt;/P&gt;
&lt;P&gt;300 stock for&amp;nbsp; &amp;nbsp; 2 € =&amp;nbsp; &amp;nbsp;600 €&lt;/P&gt;
&lt;P&gt;50 stock for&amp;nbsp; &amp;nbsp; &amp;nbsp; 3 € =&amp;nbsp; &amp;nbsp;150 €&lt;/P&gt;
&lt;P&gt;500 stock for&amp;nbsp; &amp;nbsp; 4 € = 2.000 €&lt;/P&gt;
&lt;P&gt;1050 stock for&amp;nbsp; 5 €=&amp;nbsp; 5.250 €&lt;/P&gt;
&lt;P&gt;Total =&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8.100 €&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added a Index column to the table and then created the following measure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Total Values (all categories) = 
//Temporary Table to calculate the cumulative values until reaching the order quantities
VAR Temporary_Table =
    ADDCOLUMNS (
        ALL ( Price_Quantity_Table[Price] );
        "Cumulatives"; CALCULATE ( SUM ( Price_Quantity_Table[Amount] ); Price_Quantity_Table[Price] &amp;lt;= EARLIER ( Price_Quantity_Table[Price] ) );
        "Index_N"; LOOKUPVALUE ( Price_Quantity_Table[Index]; Price_Quantity_Table[Price]; Price_Quantity_Table[Price] );
        "Quantity"; LOOKUPVALUE ( Price_Quantity_Table[Amount]; Price_Quantity_Table[Price]; Price_Quantity_Table[Price] )
    )

//Quantity selection of the order based on cumulatives values
VAR Quantity_Selection =
    CALCULATE (
        MAX ( Price_Quantity_Table[Amount] );
        FILTER ( Temporary_Table; [Cumulatives] &amp;lt;= Parameter[Parameter Value] )
    )

//Index column for the quantity selection
VAR Index_Selection =
    CALCULATE (
        MAX ( Price_Quantity_Table[Index] );
        FILTER ( Temporary_Table; [Cumulatives] &amp;lt;= Parameter[Parameter Value] )
    )

//First Quantity above the desired quantity to be used for the price of the last part of the fullfilment
VAR Quantity_Selection_Above =
    CALCULATE (
        MAX ( Price_Quantity_Table[Amount] );
        FILTER ( Temporary_Table; [Index_N] = Index_Selection + 1 )
    )

//Cumulative quantity to calculate the difference between quantity of order and the last price 
VAR Quantity_Cumulative =
    CALCULATE (
        SUMX ( Price_Quantity_Table; Price_Quantity_Table[Amount] );
        FILTER ( Price_Quantity_Table; Price_Quantity_Table[Index] &amp;lt;= Index_Selection )
    )

//Price for the last quantity to be fulfill
VAR Price_Selection_Above =
    CALCULATE (
        MAX ( Price_Quantity_Table[Price] );
        FILTER ( Temporary_Table; [Index_N] = Index_Selection + 1 )
    )
RETURN
    CALCULATE (
        SUMX ( Price_Quantity_Table; Price_Quantity_Table[Amount] * Price_Quantity_Table[Price] );
        FILTER ( Temporary_Table; [Cumulatives] &amp;lt;= Parameter[Parameter Value] )
    ) + ( ( Parameter[Parameter Value] - Quantity_Cumulative ) * Price_Selection_Above )&lt;/PRE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If someone has other ideas on how to do this please share.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;MFelix&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="reportid hidden"&gt;eyJrIjoiZDBlMmZlZDItY2QyNy00MzlkLTgxODEtODc1NDc2MDE2YjBlIiwidCI6IjczNGQyYTI3LThjODktNDMyOC1iZTYwLTRhMWQxMWNkNWM3OCIsImMiOjl9&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 06 May 2019 23:07:37 GMT</pubDate>
    <dc:creator>MFelix</dc:creator>
    <dc:date>2019-05-06T23:07:37Z</dc:date>
    <item>
      <title>Calculate amounts by order</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Calculate-amounts-by-order/m-p/684847#M341</link>
      <description>&lt;P&gt;This come up from a post on the community, were it was needed to calculate the total price for orders based on a quantity / price table were the order of the table was by price:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="width: 95px;"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;Amount&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;Price&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;100&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€1,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;300&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€2,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;50&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€3,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;500&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€4,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;8000&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€5,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;900&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€6,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;2700&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€7,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;4700&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€8,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD style="width: 46px;"&gt;6000&lt;/TD&gt;
&lt;TD style="width: 49px;"&gt;€9,00&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The idea was if someone asked for 2000 units the order was fulfilled based on the lowest price until reaching the 2000 units so would be something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;100 stock for&amp;nbsp; &amp;nbsp; 1 € =&amp;nbsp; &amp;nbsp;100 €&lt;/P&gt;
&lt;P&gt;300 stock for&amp;nbsp; &amp;nbsp; 2 € =&amp;nbsp; &amp;nbsp;600 €&lt;/P&gt;
&lt;P&gt;50 stock for&amp;nbsp; &amp;nbsp; &amp;nbsp; 3 € =&amp;nbsp; &amp;nbsp;150 €&lt;/P&gt;
&lt;P&gt;500 stock for&amp;nbsp; &amp;nbsp; 4 € = 2.000 €&lt;/P&gt;
&lt;P&gt;1050 stock for&amp;nbsp; 5 €=&amp;nbsp; 5.250 €&lt;/P&gt;
&lt;P&gt;Total =&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8.100 €&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added a Index column to the table and then created the following measure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Total Values (all categories) = 
//Temporary Table to calculate the cumulative values until reaching the order quantities
VAR Temporary_Table =
    ADDCOLUMNS (
        ALL ( Price_Quantity_Table[Price] );
        "Cumulatives"; CALCULATE ( SUM ( Price_Quantity_Table[Amount] ); Price_Quantity_Table[Price] &amp;lt;= EARLIER ( Price_Quantity_Table[Price] ) );
        "Index_N"; LOOKUPVALUE ( Price_Quantity_Table[Index]; Price_Quantity_Table[Price]; Price_Quantity_Table[Price] );
        "Quantity"; LOOKUPVALUE ( Price_Quantity_Table[Amount]; Price_Quantity_Table[Price]; Price_Quantity_Table[Price] )
    )

//Quantity selection of the order based on cumulatives values
VAR Quantity_Selection =
    CALCULATE (
        MAX ( Price_Quantity_Table[Amount] );
        FILTER ( Temporary_Table; [Cumulatives] &amp;lt;= Parameter[Parameter Value] )
    )

//Index column for the quantity selection
VAR Index_Selection =
    CALCULATE (
        MAX ( Price_Quantity_Table[Index] );
        FILTER ( Temporary_Table; [Cumulatives] &amp;lt;= Parameter[Parameter Value] )
    )

//First Quantity above the desired quantity to be used for the price of the last part of the fullfilment
VAR Quantity_Selection_Above =
    CALCULATE (
        MAX ( Price_Quantity_Table[Amount] );
        FILTER ( Temporary_Table; [Index_N] = Index_Selection + 1 )
    )

//Cumulative quantity to calculate the difference between quantity of order and the last price 
VAR Quantity_Cumulative =
    CALCULATE (
        SUMX ( Price_Quantity_Table; Price_Quantity_Table[Amount] );
        FILTER ( Price_Quantity_Table; Price_Quantity_Table[Index] &amp;lt;= Index_Selection )
    )

//Price for the last quantity to be fulfill
VAR Price_Selection_Above =
    CALCULATE (
        MAX ( Price_Quantity_Table[Price] );
        FILTER ( Temporary_Table; [Index_N] = Index_Selection + 1 )
    )
RETURN
    CALCULATE (
        SUMX ( Price_Quantity_Table; Price_Quantity_Table[Amount] * Price_Quantity_Table[Price] );
        FILTER ( Temporary_Table; [Cumulatives] &amp;lt;= Parameter[Parameter Value] )
    ) + ( ( Parameter[Parameter Value] - Quantity_Cumulative ) * Price_Selection_Above )&lt;/PRE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If someone has other ideas on how to do this please share.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;MFelix&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="reportid hidden"&gt;eyJrIjoiZDBlMmZlZDItY2QyNy00MzlkLTgxODEtODc1NDc2MDE2YjBlIiwidCI6IjczNGQyYTI3LThjODktNDMyOC1iZTYwLTRhMWQxMWNkNWM3OCIsImMiOjl9&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 23:07:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Calculate-amounts-by-order/m-p/684847#M341</guid>
      <dc:creator>MFelix</dc:creator>
      <dc:date>2019-05-06T23:07:37Z</dc:date>
    </item>
  </channel>
</rss>

