USERELATIONSHIP filter question

macfuller

Active Member
Joined
Apr 30, 2014
Messages
251
I've got a measure where I'd like to have a USERELATIONSHIP clause in the CALCULATE. The code below works... however, I'm not clear why I can't add the USERELATIONSHIP as a filter parameter to the "inner" CALCULATE. If I do that without the outer CALCULATE the measure returns blank<blank>.
Code:
Discount Taken Total :=CALCULATE (
    CALCULATE (
        SUM ( Vouchers[Discount Amount] ),
        FILTER (
            Vouchers,
            NOT (
                ISBLANK ( Vouchers[Discount Due Date] )
            )
                && NOT (
                    ISBLANK ( Vouchers[Payment Date] )
                )
                && Vouchers[Discount Due Date] >= Vouchers[Payment Date]
        )
    ),
    USERELATIONSHIP ( Vouchers[Payment Date], 'AP Calendar'[Date] )
)
The AP Calendar table is a standard date table - the default relationship is to the Voucher Entered Date, but as I'm tracking discount payments I need to group my spend as of the payment date.
In order to receive a discount (e.g. 2% 10 days) we must pay prior to or on the discount due date.
The Payment Date is blank if vouchers have not been paid.
The Discount Date is blank if we do not offer a discount for that vendor.</blank>
 

VBA Geek

MrExcel MVP
Joined
Dec 16, 2013
Messages
2,857
You measure works because the table Vouchers, on which you are iterating using FILTER, is calculated within the context of the relationship between Vouchers[Payment Date] and 'AP Calendar'[Date], and not in the context of the active relationship.
On the other hand, if you use USERELATIONSHIP inside the inner calculate, then the table Vouchers, on which you are iterating using FILTER, is calculated in the context of the active relationship and the intersection between the result of FILTER and USERELATIONSHIP does not return anything in your case.
 

macfuller

Active Member
Joined
Apr 30, 2014
Messages
251
The FILTER should return records that have a Payment date since I'm looking for non-blank values. So I would think there should be an intersection as the calendar table has 3 years of values thru Dec 2019 (for projected measures)? Does the order of the relationship parameters in USERELATIONSHIP matter?
 

VBA Geek

MrExcel MVP
Joined
Dec 16, 2013
Messages
2,857
Normally as first argument you would use the column from the many side and as second argument the column from the one side. But if you place them incorrectly I believe DAX will correct them for you
 

Forum statistics

Threads
1,081,973
Messages
5,362,508
Members
400,677
Latest member
champchamp

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top