Incorrect measure result mystery

macfuller

Active Member
Joined
Apr 30, 2014
Messages
319
Office Version
  1. 365
Platform
  1. Windows
I have a measure to determine how many invoices are arriving late to our AP offices.
VBA Code:
Pct of Invoices Recvd in AP >14 Days:=
VAR IsLate = 15
VAR LateVouchers =
    CALCULATE (
        DISTINCTCOUNT ( Vouchers[Invoice_Key] ),
        Vouchers[Invoice to Entry Days] >= IsLate
    )
VAR AllVouchers =
    DISTINCTCOUNT(Vouchers[Invoice_Key])
VAR Ratio =
    CALCULATE (
       DIVIDE (
            LateVouchers,
            AllVouchers
        ),
        USERELATIONSHIP ( Vouchers[Account], 'Account Tree'[Account] ),
        USERELATIONSHIP ( Vouchers[Dept ID], '3PL Cost Centers'[Center] ),
        USERELATIONSHIP ( Vouchers[Dept ID], Depts[Dept] ),
        USERELATIONSHIP ( Vouchers[Voucher Entered Date], AP_Calendar[Date] )
    ) 
RETURN
   Ratio
However, this measure returns 100% - the numerator and denominator are the same. For a given department, 17 of 46 invoices were delivered after 15 days, but the AllVouchers variable is coming in at 17.

If I use a separate measure for the invoice count
VBA Code:
Invoice Count:=CALCULATE( 
    DISTINCTCOUNT(Vouchers[Invoice_Key]),
    USERELATIONSHIP ( Vouchers[Account], 'Account Tree'[Account] ),
    USERELATIONSHIP ( Vouchers[Dept ID], '3PL Cost Centers'[Center] ),
    USERELATIONSHIP ( Vouchers[Dept ID], Depts[Dept] ),
    USERELATIONSHIP ( Vouchers[Voucher Entered Date], 'AP_Calendar'[Date] )
    )
and then adjust the first measure to use that measure as the denominator
VBA Code:
Pct of Invoices Recvd in AP >14 Days:=
VAR IsLate = 15
VAR LateVouchers =
    CALCULATE (
        DISTINCTCOUNT ( Vouchers[Invoice_Key] ),
        Vouchers[Invoice to Entry Days] >= IsLate
    )
VAR Ratio =
    CALCULATE (
       DIVIDE (
            LateVouchers,
            [Invoice Count]
        ),
        USERELATIONSHIP ( Vouchers[Account], 'Account Tree'[Account] ),
        USERELATIONSHIP ( Vouchers[Dept ID], '3PL Cost Centers'[Center] ),
        USERELATIONSHIP ( Vouchers[Dept ID], Depts[Dept] ),
        USERELATIONSHIP ( Vouchers[Voucher Entered Date], AP_Calendar[Date] )
    ) 
RETURN
   Ratio
I get the correct result. Anyone have a clue why I'm getting it wrong with the first option?
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Because when you use VAR AllVouchers = DISTINCTCOUNT(Vouchers[Invoice_Key]), the variable has already been evaluated for distinct counts without any modification in the relationships, and when you use this variable inside CALCULATE, the CALCULATE can't modify the filter context for a variable as it has already been evaluated but, with the other one the story is different as the Invoice count measure is modified with the USERELATIONSHIP, also Instead of creating a separate measure in case if you do not use it for other calculations use could also just replace [Invoice Count] with DISTINCTCOUNT(Vouchers[Invoice_Key])
 
Upvote 0
Solution

Forum statistics

Threads
1,223,791
Messages
6,174,603
Members
452,574
Latest member
hang_and_bang

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top