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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
chat_peters
Helper III
Helper III

Aggregation with USERELATIONSHIP

I have data model with 4 tables (I don't have much freedom to make changes to it)

 Order Fact, Buyer Dim, Caller Dim and People Dim. Sometimes the buyer and the caller can be the same person and sometime they are different people. Now I am using USERELATIONSHIP to get a count of orders and putting it in a grid visual to show all the records. The whole point of USERELATIONSHIP is to get the location to respond to both buyers and callers (to show the actual number of orders tied to a location regardless of who (buyer or caller) is tied to that order. This works out perfect in the grid visual but goes horribly wrong in other visuals) Not elegant, but works. My question is how do I get it to count all the rows where the buyer is not the same as the caller or the instances where they're the same. 

chat_peters_0-1648146291306.png

chat_peters_2-1648147246411.png

 

inactiverelationshipmeasure = CALCULATE('Order Fact'[Total Orders],USERELATIONSHIP(BuyerDim[BuyerID],'PeopleDim'[Id]))
Total Orders = COUNT('Order Fact'[Order ID])

 

In the above visual the total row count should be 7. How do I go about achieving that? I've tried keepfilters to no avail. I want to count all the rows using userelationship measure where BuyerID = CallerID or BuyerID <> CallerID. Thank you in advance for taking your time to read this post. I created two columns, then tried to pass these columns as filters into my userelationship measure, but it didn't work. I am on direct query mode in ssas and operators such as IN don't work for me 😞

 

Caller different Buyer = IF('Order Fact'[CallerID]<>'Order Fact'[BuyerID],1,0)
Caller same Buyer = IF('Order Fact'[CallerID]='Order Fact'[BuyerID],1,0)
Total Orders NEW(Wrong-gives me a blanks) = CALCULATE(COUNTROWS('Order Fact'),
                    USERELATIONSHIP(BuyerDim[BuyerID],PeopleDim[Id]),
                    KEEPFILTERS('Order Fact'[Caller same Buyer]=1),
                    KEEPFILTERS('Order Fact'[Caller different Buyer]=1)
)

 

Link to sample file: https://www.dropbox.com/s/rte1zs13csx4ghz/example2.pbix?dl=0 

 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @chat_peters ,

 

Is what you want something like this?

Measure =
COUNT ( 'Order Fact'[Order ID] )
    + CALCULATE (
        COUNT ( 'Order Fact'[Order ID] ),
        USERELATIONSHIP ( 'PeopleDim'[Id], BuyerDim[BuyerID] ),
        'Order Fact'[Caller different Buyer] = 1
    )

Icey_0-1648458220205.png

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
chat_peters
Helper III
Helper III

This solution works great. I am going with @Icey's solution for now because it works with all the other filters and in the direct query mode and the outdated version of power bi I am working with. I made tiny tweak to the formula 

Measure =
CALCULATE(COUNT( 'Order Fact'[Order ID] ), 'Order Fact'[Caller Buyer Same] =1)
    + CALCULATE (
        COUNT ( 'Order Fact'[Order ID] ),
        USERELATIONSHIP ( 'PeopleDim'[Id], BuyerDim[BuyerID] ),
        'Order Fact'[Caller different Buyer] = 1
    )

Thank you @Icey so much😊

Icey
Community Support
Community Support

Hi @chat_peters ,

 

Is what you want something like this?

Measure =
COUNT ( 'Order Fact'[Order ID] )
    + CALCULATE (
        COUNT ( 'Order Fact'[Order ID] ),
        USERELATIONSHIP ( 'PeopleDim'[Id], BuyerDim[BuyerID] ),
        'Order Fact'[Caller different Buyer] = 1
    )

Icey_0-1648458220205.png

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

chat_peters
Helper III
Helper III

I made this measure but it's not working, it's only taking into consideration when the buyer is the same as caller. 

Total Orders with filter_2 = CALCULATE(
                                COUNT('Order Fact'[Order ID]),
                                USERELATIONSHIP(BuyerDim[BuyerID],PeopleDim[Id]),
                                FILTER(
                                    'Order Fact',
                                    OR(
                                        'Order Fact'[Caller different Buyer]=1,
                                         'Order Fact'[Caller same Buyer]=1
)))

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors