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
pbix
Helper III
Helper III

Comparing two dates using one calendar table and USERELATIONSHIP

Hi All, 

 

I want to compare two dates in a single measure to return a count of where delivery date > estimated delivery date within a period.

 

I have two tables:

 

1) Fact Sales ([Order ID], [Est Delivery Date ID], [Delivery Date ID])

2) Dim Date ([D Date ID], [D Date])

 

I can return a counts of [est delivery date] and [delivery date] each day/month/year using:

 

Count of estimated:CALCULATE(COUNTA([ORDER ID]),USERELATIONSHIP([EST DELIVERY DATE ID], [D DATE ID])

Count of deliveries:CALCULATE(COUNTA([ORDER ID]),USERELATIONSHIP([DELIVERY DATE ID], [D DATE ID])

 

However I want to now compare the two date fileds to return a count of late deliveries (EDD > DD). If I used two separate date dimensions for EDD and DD I could just use similar to:

 

SUMX('FACT SALES',IF( RELATED(DD_DIMENSION[DATE]) >RELATED(EDD_DIMENSION[DATE]),1,0))

 

How can I replicate this formula using USERELATIONSHIP?

 

In SQL Terms this would be equal to:

 

Select 

Period,

Sum(Case when EDD>DD then 1 else 0 end)

From

Table

Group by

Period

 

Thanks!

 

Pbix

13 REPLIES 13

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.

Top Solution Authors