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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply

Problem with USERELATIONSHIP

I'm trying to create a measure to get Sales Amount w.r.t Delivered Date where CalenderYear is 2007 but having trouble with same.

 

For Sales Amount w.r.t Delivered Date works well  and show amount for Delivered Date CY 2007 with UserRelationship, but when i try to filter only for 2007 its show blank rows Man Surprised Man Frustrated.

 

user relationship w.r.t  Deliver Date CY not workinguser relationship w.r.t Deliver Date CY not working

 

I'm using ContosoDw for reference and below is code of two measure.

 

Sales w.r.t Delivered Date

Delivered Amount = 
CALCULATE (
[SalesAmount],
USERELATIONSHIP ( Sales[DeliveryDateKey], 'Date'[DateKey] )
)

Sales w.r.t to DeliveredDate for Year 2007

Delivered Amount in 2007 = 
CALCULATE (
[Sales Amount],
FILTER (
CALCULATETABLE (
Sales,
USERELATIONSHIP( Sales[DeliveryDateKey], 'Date'[DateKey] )
),
RELATED ( 'Date'[Calendar Year Number] ) = 2007
)
)

 

1 ACCEPTED SOLUTION
avanderschilden
Resolver I
Resolver I

Hello,

 

Try this (with the correct table and column names from your model) ;

Delivered Amount 2007 =
CALCULATE(
SUM(Sales[Amount]),
USERELATIONSHIP('Date'[Date],Sales[DeliveryDate]),
YEAR(Sales[DeliveryDate])=2007
)
 
Let me know!
 
Regards,
 
Adrian

View solution in original post

6 REPLIES 6
avanderschilden
Resolver I
Resolver I

Hello,

 

Try this (with the correct table and column names from your model) ;

Delivered Amount 2007 =
CALCULATE(
SUM(Sales[Amount]),
USERELATIONSHIP('Date'[Date],Sales[DeliveryDate]),
YEAR(Sales[DeliveryDate])=2007
)
 
Let me know!
 
Regards,
 
Adrian

Hi Adrian,

 

Its showing below error (USERRELATIONSHIP function can only use the two columns references participating in relationship), while using your concept. I've replaced SUM(Sales[Amount]) with measure already build.

Which is using an  below code as an expression 

SUMX(Sales,Sales[Quantity]*Sales[Unit Price])

 

UserRelationShipIssue_06142019.png

Great! So it is solved right?

Yeah it worked, and last error was due to wrong column used for relationship.

 

The only thing is ,its only showing for CY2007 and not repeating for all CY.

 

UserRelationShip_06142019.png

This will show the delivered amount in 2017 on all year lines;

 

Delivered Amount 2017 =
CALCULATE([Delivered Amount],
YEAR('Date'[Date])=2018)

yeah @avanderschilden  changing your first expression from 

CALCULATE(
[SalesAmount],// its a measure with expression SUMX(Sales,Sales[Quantity]*Sales[Unit Price])
USERELATIONSHIP('Date'[DateKey],Sales[DeliveryDateKey]),
YEAR('Date'[Date])=2007 // Changed from YEAR(Sales[DeliveryDate])=2007 allowed 2007 sales w.r.t to delivered date on all CY
)

Thanks for your guidance, much appreciated Man Happy

 

Regards,

Harry

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors