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
Anonymous
Not applicable

Calculate sum of cells based on date/time combinations

Hello,

 

I am trying to create a measurement which is based on transportation order data. The data can be stated in the following way:

 

Order numberOrder delivery dateOrder creation dateOrder creation timeWeight (kg)
324202-02-202030-01-202008:153
124102-02-202031-01-202016:302
124902-02-202001-02-202012:305
425502-02-202001-02-202017:001
333103-02-202001-02-202016:003
365403-02-202002-02-202013:004
723103-02-202002-02-202016:302
...............

 

In my case, 90% of the orders arrive the day before the delivery date. For each order delivery date, I would like to calculate the weight level of all orders combined for the day preceding the delivery date at specific moments in time. I would like to create the following table:

 

Order delivery dateWeight level preceding day order delivery date (before 12:00)Weight level preceding day order delivery date (before 16:00)Weight level preceding day order delivery date (before 20:00)
02-02-202051011
03-02-2020379
............

 

Could someone help me with this case? I have tried to sum the weight by comparing the date/time combinations of orders, but I did not manage to solve it. Thank you.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi

It would be far easier if you could add a column to your order that cohort your data by hours.
So, in this example, add a column
OrderCohort=
IF(
   Order[Order creation time]<=12;12;
  IF (Order[Order creation time]<=16; 16;
  IF (Order[Order creation time]<=20; 20;24)))

(please note, I write pseudocode on the fly, so fix the syntax as needed)
(also you can achieve and it would be much easier with a SWITCH(TRUE()) construct)

You can now create a matrix with DATE in the ROW and OrderCohort in the columns

Then your measure in the value will be Weight=SUMX(Order;Order[Weight])

View solution in original post

6 REPLIES 6
FrankAT
Community Champion
Community Champion

Hi,

take a look a the following figure:

 

19-02-_2020_16-36-09.png

 

Regards FrankAT

Anonymous
Not applicable

Hi

It would be far easier if you could add a column to your order that cohort your data by hours.
So, in this example, add a column
OrderCohort=
IF(
   Order[Order creation time]<=12;12;
  IF (Order[Order creation time]<=16; 16;
  IF (Order[Order creation time]<=20; 20;24)))

(please note, I write pseudocode on the fly, so fix the syntax as needed)
(also you can achieve and it would be much easier with a SWITCH(TRUE()) construct)

You can now create a matrix with DATE in the ROW and OrderCohort in the columns

Then your measure in the value will be Weight=SUMX(Order;Order[Weight])

Anonymous
Not applicable

@Anonymous, I have managed to solve my problem with your help. Thank you.

Anonymous
Not applicable

Dear @Anonymous,

 

Thank you for your message. I have tried to implement your suggestion. It partly works. I would like to calculate the weight level for the day preceding the delivery day. Your suggestion calculates the weights up to the desired time stamp. However, when one order is created 3 days before the delivery date at 17:30, it is recorded as being between 16:00 and 20:00. However, the order should be recorded as being before 12:00 the day preceding the delivery day, since the order was created 3 days before. I hope you could help me.

 

Also, since I only have weekdays (and no subsequent dates because of the weekends), this might impede finding a working solution.

 

Anonymous
Not applicable

So this solution takes all the orders DELIVERED on a day up to that time and sum the weight.
You want to calculate all the orders DELIVERED ON THE PREVIOUS DAY (and only previous day) up to that time.

 

Do you have a date dimension? If not, please create it (look up on the web "how to create a date dimension in powerbi") 

Anonymous
Not applicable

Dear @Anonymous,

 

90% of the orders at a transportation company arrive the day preceding the delivery day. So, most customers order today and would like to receive their order tomorrow. I would like to track the weight level at specific moments in time on the day preceding the delivery day, more specifically at 12:00, 16:00, and 20:00. So, I can track how the weight level that is to be delivered tomorrow evolves over time. 10% of the orders may have been created two days preceding the delivery day, and should be taken into account being before 12:00 at the day preceding the delivery day. I hope that I clarified my case.

 

I do not have a date dimension yet, which I can do.

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.