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
prekapRev
Frequent Visitor

Counts based on multiple dates in a table

I have a table with multiple date fields (Order Date, Ship Date, Delivery Date). I need to report on counts of sales, shipment and delivery for each month where either sale, shipment or delivery was made. 

 

Here is an example of mockup source data

Sales_Order_NumProductOrder_DateShip_DateDelivery_Date
1P18/19/20208/29/20209/3/2020
2P18/24/20209/3/20209/13/2020
3P19/3/20209/8/20209/19/2020

 

I need to display counts like this

MonthOrder CountShipment CountDelivery Count
August210
September123

 

I have a date table and created one active (on Order date) and 2 indirect (ship and delivery date) relations.

I created measures for shipment and Delivery counts using USERELATIONSHIP like below

 

Ship_Count = CALCULATE(count(Sales[Sales_Order_No]), USERELATIONSHIP(Cal_Date[Date], Sales[Ship_Date]))
Delivery_Count = CALCULATE(count(Sales[Sales_Order_No]), USERELATIONSHIP(Cal_Date[Date], Sales[Delivery_Date]))
 
But I am still getting result like below (shipment and Delivery counts are same as order count)
 

Month is from Calendar table

MonthOrder CountShipment CountDelivery Count
August222
September111

 

How do I get the shipment and delivery counts displayed correctly?

1 ACCEPTED SOLUTION

Hi @prekapRev  -

 

Force your relationships between Cal_Date and Sales to be 1-to-many (Cal_Date on the 1 side) and it should work for you.

 

2020-08-21 09_18_04-Multi_Dates - Power BI Desktop.png

 

2020-08-21 09_19_53-Multi_Dates - Power BI Desktop.png

 

Hope this helps

David

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
dedelman_clng
Community Champion
Community Champion

Hi @prekapRev  - I cannot reproduce your results. I get your expected output when I put your code in (although the DAX says "Sales Order No", while the data says "Sales Order Num", but I assume that was just an error in typing).

 

2020-08-20 15_15_51-scratch2 - Power BI Desktop.png

 

Order Count = CALCULATE(COUNT(Sales[Sales_Order_Num]))

Ship_Count = CALCULATE(count(Sales[Sales_Order_Num]), 
               USERELATIONSHIP(DateTab[Date], Sales[Ship_Date]))

Delivery_Count = CALCULATE(count(Sales[Sales_Order_Num]), 
               USERELATIONSHIP(DateTab[Date], Sales[Delivery_Date]))

 

2020-08-20 15_19_20-scratch2 - Power BI Desktop.png

 

Perhaps you left something out of the explanation that makes the situation more complicated?

 

David

 

 

@dedelman_clng I want to attach my pbix file but I don't know how to attach any files here. I have done it exactly like you are showing in your solution but my result is different. not sure why.

Put it on a Dropbox, google drive or OneDrive and put the link into a post. 

Hi @prekapRev  -

 

Force your relationships between Cal_Date and Sales to be 1-to-many (Cal_Date on the 1 side) and it should work for you.

 

2020-08-21 09_18_04-Multi_Dates - Power BI Desktop.png

 

2020-08-21 09_19_53-Multi_Dates - Power BI Desktop.png

 

Hope this helps

David

Changing cardinality fixed the problem. Thanks! I wonder though that why should that be the problem 🤔

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.