Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mhsieh
Helper II
Helper II

USERELATIONSHIP, FILTER, CALCULATE, COUNT

Hi all,

I have 3 tables

'CALENDAR LOOKUP'[Date]   to   OPPORTUNITY_INFO[SUBMITTED_DATE]    -> inactive relationship
'CALENDAR LOOKUP'[Date]   to   OPPORTUNITY_INFO[CREATED_DATE]        -> active relationship

mhsieh_0-1664905089424.png

 

I have a slicer that's using 'CALENDAR LOOKUP'[Date]

mhsieh_2-1664904904524.png

 

I am trying to get the COUNT of the OPPORTUNITY_ID with the below crietera:
- SUBMITTED_DATE in the last 30 days

OPPORTUNITY_INFO[CONVERTED_FROM_LEAD] = "Yes"
CAMPAIGN_LOOKUP[CAMPAIGN_TYPE] IN {"Email", "Lead Generation", "Paid Search", "Seminar / Conference", "Website"}

 

Below is the DAX code that I have at the moment, it's not giving me the correct result. (now it's giving me 141, but it should be more than 200). I am not sure how to correctly use USERELATIONSHIP + FILTER(), could anyone please let me know where I did wrong in my DAX code?

 

test = 
CALCULATE(
    DISTINCTCOUNT(OPPORTUNITY_INFO[OPPORTUNITY_ID]),
    USERELATIONSHIP(OPPORTUNITY_INFO[SUBMITTED_DATE], 'CALENDAR LOOKUP'[Date]),
    FILTER(
        OPPORTUNITY_INFO,
        OPPORTUNITY_INFO[CONVERTED_FROM_LEAD] = "Yes" &&
        RELATED(CAMPAIGN_LOOKUP[CAMPAIGN_TYPE]) IN {"Email", "Lead Generation", "Paid Search", "Seminar / Conference", "Website"}
    )
)

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I'm pretty sure the issue is that USERELATIONSHIP is not being applied to OPPORTUNITY_INFO inside the FILTER. There are ways to fix that but I think you might be able to bypass that problem entirely by changing your filter conditions.

 

Try this:

CALCULATE (
    DISTINCTCOUNT ( OPPORTUNITY_INFO[OPPORTUNITY_ID] ),
    OPPORTUNITY_INFO[CONVERTED_FROM_LEAD] = "Yes",
    CAMPAIGN_LOOKUP[CAMPAIGN_TYPE]
        IN { "Email", "Lead Generation", "Paid Search", "Seminar / Conference", "Website" },
    USERELATIONSHIP ( OPPORTUNITY_INFO[SUBMITTED_DATE], 'CALENDAR LOOKUP'[Date] )
)

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

I'm pretty sure the issue is that USERELATIONSHIP is not being applied to OPPORTUNITY_INFO inside the FILTER. There are ways to fix that but I think you might be able to bypass that problem entirely by changing your filter conditions.

 

Try this:

CALCULATE (
    DISTINCTCOUNT ( OPPORTUNITY_INFO[OPPORTUNITY_ID] ),
    OPPORTUNITY_INFO[CONVERTED_FROM_LEAD] = "Yes",
    CAMPAIGN_LOOKUP[CAMPAIGN_TYPE]
        IN { "Email", "Lead Generation", "Paid Search", "Seminar / Conference", "Website" },
    USERELATIONSHIP ( OPPORTUNITY_INFO[SUBMITTED_DATE], 'CALENDAR LOOKUP'[Date] )
)

This works! Thank you so much @AlexisOlson

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.