<?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: Multiplication with different granularities in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1311660#M22905</link>
    <description>&lt;P&gt;Not sure if this is what you wanted... but you can take it and shape it into something you want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// Let's assume that
// 1. You've got an Orders table with
//    orders in there OrderID, ItemID, OrderStatus
//    where OrderStatus is the same for all lines
//    with the same OrderID.
// 2. You've got an OrderItems table with
//    items that belong to an order from the
//    Orders table (ItemID is unique across all Orders)
//    The columns in OrderItems are
//    ItemID, Area, Delivery, TimeValue
// An open order is one that has OrderStatus &amp;lt; 70 in
// Orders.
// Relationship: Orders[ItemID] * &amp;lt;-one-way- 1 OrderItems[ItemID]. 
// One order can have multiple items but each item in
// OrderItems can belong to only one order.
//
// The above setup is a bit strange. What it really should be
// is this.
// Orders - stores data on orders and each line is one order.
// Items  - stores all available items that an order can contain.
// Order2Item - stores the relationship between an order and an item.

[# Open Orders] =
CALCULATE(
    DISTINCTCOUNT( Order[OrderID] ),
    KEEPFILTERS( Order[Status] &amp;lt; 70 )
)

[Avg Delivery Time Per Order] =
IF( HASONEVALUE( Orders[OrderID] ),
    AVERAGE( OrderItems[Delivery Time] )
)

[Avg Delivery Time Per Open Order] =
IF( [# Open Orders] = 1,
    AVERAGE( OrderItems[Delivery Time] )
)

[Avg Delivery Time] =
    AVERAGEX(
        VALUES( Order[OrderID] ),
        [Avg Delivery Time Per Order]
    )
    
[Avg Delivery Time for Open Orders] =
    AVERAGEX(
        VALUES( Order[OrderID] ),
        [Avg Delivery Time Per Open Order]
    )

[Final Measure] =
    [Avg Delivery Time for Open Orders]
    * [# Open Orders]&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 20 Aug 2020 15:23:27 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-08-20T15:23:27Z</dc:date>
    <item>
      <title>Multiplication with different granularities</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1310848#M22871</link>
      <description>&lt;P&gt;Hello everyone!&lt;/P&gt;&lt;P&gt;I have to calculate the average delivery time multiplied by the Number of open Orders.&lt;/P&gt;&lt;P&gt;I have the following two tables:&lt;/P&gt;&lt;P&gt;tblItemMaster&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Item&lt;/TD&gt;&lt;TD&gt;Area&lt;/TD&gt;&lt;TD&gt;Delivery Time&lt;/TD&gt;&lt;TD&gt;Value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;500&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tblOrder&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Order&lt;/TD&gt;&lt;TD&gt;Item&lt;/TD&gt;&lt;TD&gt;Status&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AA1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this purpose I have two measures.&lt;/P&gt;&lt;P&gt;The first one to determine the number of Orders open (Status &amp;lt; 70).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;# Order= CALCULATE(
    COUNTROWS( tblOrder),
    ALL( 'Calendar' ),
    tblOrder[Status] &amp;lt; 70
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then I have an Avere function to determine the average delivery time:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Delivery Time = AVERAGE('tblItemMaster'[Delivery Time])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With a simple measure like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Test = Delivery Time*[# Orders]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; I get a false result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to calculate this on the Area-level, not on Article Level.&lt;/P&gt;&lt;P&gt;For this I choose average, right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What did I forget?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 11:30:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1310848#M22871</guid>
      <dc:creator>joshua1990</dc:creator>
      <dc:date>2020-08-20T11:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with different granularities</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1310865#M22872</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92006" data-lia-user-login="joshua1990" class="lia-mention lia-mention-user"&gt;joshua1990&lt;/a&gt;&amp;nbsp;- Not sure I understand. I assume you have a relationship between your 2 tables, correct? On Item? Also, you are placing Area in your visual, correct? Any chance you can share an example PBIX?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 11:33:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1310865#M22872</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-08-20T11:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with different granularities</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1311021#M22877</link>
      <description>Please give some MEANINGFUL example. The amount of data you've shown is not enough. By the way, if there are multiple items on an order and they get delivered at different times, then I think you'll first have to calculate the average delivery time per one order (so averaging over items of the order) and then average these averages (over orders) and then multiply this average by the number of orders.</description>
      <pubDate>Thu, 20 Aug 2020 12:17:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1311021#M22877</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-20T12:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with different granularities</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1311539#M22901</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92006" data-lia-user-login="joshua1990" class="lia-mention lia-mention-user"&gt;joshua1990&lt;/a&gt; , not sure I got it. You are filtering order #. no filter in avg time. So the number will not match with sum &lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 14:41:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1311539#M22901</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2020-08-20T14:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Multiplication with different granularities</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1311660#M22905</link>
      <description>&lt;P&gt;Not sure if this is what you wanted... but you can take it and shape it into something you want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// Let's assume that
// 1. You've got an Orders table with
//    orders in there OrderID, ItemID, OrderStatus
//    where OrderStatus is the same for all lines
//    with the same OrderID.
// 2. You've got an OrderItems table with
//    items that belong to an order from the
//    Orders table (ItemID is unique across all Orders)
//    The columns in OrderItems are
//    ItemID, Area, Delivery, TimeValue
// An open order is one that has OrderStatus &amp;lt; 70 in
// Orders.
// Relationship: Orders[ItemID] * &amp;lt;-one-way- 1 OrderItems[ItemID]. 
// One order can have multiple items but each item in
// OrderItems can belong to only one order.
//
// The above setup is a bit strange. What it really should be
// is this.
// Orders - stores data on orders and each line is one order.
// Items  - stores all available items that an order can contain.
// Order2Item - stores the relationship between an order and an item.

[# Open Orders] =
CALCULATE(
    DISTINCTCOUNT( Order[OrderID] ),
    KEEPFILTERS( Order[Status] &amp;lt; 70 )
)

[Avg Delivery Time Per Order] =
IF( HASONEVALUE( Orders[OrderID] ),
    AVERAGE( OrderItems[Delivery Time] )
)

[Avg Delivery Time Per Open Order] =
IF( [# Open Orders] = 1,
    AVERAGE( OrderItems[Delivery Time] )
)

[Avg Delivery Time] =
    AVERAGEX(
        VALUES( Order[OrderID] ),
        [Avg Delivery Time Per Order]
    )
    
[Avg Delivery Time for Open Orders] =
    AVERAGEX(
        VALUES( Order[OrderID] ),
        [Avg Delivery Time Per Open Order]
    )

[Final Measure] =
    [Avg Delivery Time for Open Orders]
    * [# Open Orders]&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 20 Aug 2020 15:23:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Multiplication-with-different-granularities/m-p/1311660#M22905</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-08-20T15:23:27Z</dc:date>
    </item>
  </channel>
</rss>

