Forum Discussion

prekapRev's avatar
prekapRev
Frequent Visitor
6 years ago
Solved

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?

  • 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.

     

     

     

    Hope this helps

    David

7 Replies

  • dedelman_clng's avatar
    dedelman_clng
    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).

     

     

    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]))

     

     

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

     

    David

     

     

    • prekapRev's avatar
      prekapRev
      Frequent Visitor

      @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.

      • dedelman_clng's avatar
        dedelman_clng
        Community Champion

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