Forum Discussion

trdoan's avatar
trdoan
Helper III
7 years ago

Measure returns wrong result

Hello everyone,

 

Here is the link to my sample data.

 

Please note in the "Data" table, each Part Number corresponds to a COE Description and there are a total of 5 COE Descriptions.

 

Table "Data" and "OPR" are linked by Part Number and Material Number columns.

 

The "OPR" table is a transaction table where everything is recorded during the last 12 months whilst the "Data" table contains the Part Numbers I want to track to see whether Supplier WF and SOA had shared any Part Numbers mentioned in the "Data" table.

 

I did the below steps (not sure if they're right):

 

1. I merged the OPR and Data table, left outer join, by 'Data'[Part Number] and 'OPR'[Material Number] and called the table 'Merge Table'

 

2. I came up with this calculated column to find the Shared Material Numbers between WF and SOA, though I'm not sure the 'Merge Table'[Material Number] or the 'Merge Table'[Part Number] already did the job(?)

 

Please help me validate if merging the 2 tables already did the job of finding which Part Numbers they shared? Or the below measure would do/would not do the job?

 

Common P/Ns = 
VAR _MN = 
CONTAINS(
    FILTER('Merge Table', 
    'Merge Table'[Vendor Name] = "SOA"),
    'Merge Table'[Material number],'Merge Table'[Material number] ) 

&& 

CONTAINS(
    FILTER('Merge Table', 
    'Merge Table'[Vendor Name] = "WF"), 
    'Merge Table'[Material number], 'Merge Table'[Material number] )

RETURN IF(_MN = TRUE, 'Merge Table'[Material number] , "")

3. I created the following measures to calculate Spend, Volume, and Average Final Run Time (known as TAT):

SPEND = 
CALCULATE(
    SUM( 'Merge Table'[Net Order Quantity] ),
    CALCULATETABLE(
        VALUES( 'Merge Table'[Material number] ),
        'Merge Table'[Vendor Name] = "SOA"
    ),
        CALCULATETABLE(
        VALUES( 'Merge Table'[Material number] ),
        'Merge Table'[Vendor Name] = "WF"
    ))
VOLUME = 
CALCULATE(
    SUM( 'Merge Table'[Order Quantity] ),
    CALCULATETABLE(
        VALUES( 'Merge Table'[Material number] ),
        'Merge Table'[Vendor Name] = "SOA"
    ),
        CALCULATETABLE(
        VALUES( 'Merge Table'[Material number] ),
        'Merge Table'[Vendor Name] = "WF"
    ))
TAT = 
CALCULATE(
    AVERAGE( 'Merge Table'[Net Order Quantity] ),
    CALCULATETABLE(
        VALUES( 'Merge Table'[Material number] ),
        'Merge Table'[Vendor Name] = "SOA"
    ),
        CALCULATETABLE(
        VALUES( 'Merge Table'[Material number] ),
        'Merge Table'[Vendor Name] = "WF"
    ))

 

4. Because I wanted to have a dynamic chart where it can show Volume, Spend, and Average Final Run Time simultaneously, I created a new table called "Measure Selection" (see the below picture)

and the following measures:

Selected Metric = SELECTEDVALUE( 'Measure Selection'[Selected Measure], "SPEND" )
Selection = 
SWITCH(TRUE(),
    'Measure Selection'[Selected Metric] = "SPEND", [SPEND],
    'Measure Selection'[Selected Metric] = "TAT", [TAT],
    'Measure Selection'[Selected Metric] = "VOLUME", [VOLUME],
BLANK() )

5. I created a Clustered column chart and a chiclet slicer using 'Measure Selection'[Selection]

 

However, the result wasn't quite accurate. When I examined April 2018's calculations using a Data table, I noticed a couple of things:

 

1. In my original dataset, Supplier SOA's Volume in April 2018 only had 7 units whilst my [Volume] measure showed 14. 

 

In the below photo, I set "Order Quantity" as "Sum" and it gave 14 units and matched the [Volume] measure's result. Still, both of them should have showned 7.

 

2. When I set "Order Quantity" as "Don't Summarise" and removed [Volume] from the data table, the result came out correctly.

 

3. But when I set "Order Quantity" as "Don't Summarise" and put back [Volume] to the data table, I got this:

 

All these calculations really wrecked my mind. Does anyone have any idea why my measure(s) did not calculate correctly? Please show me how to fix this. Thank you very much!

2 Replies