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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Dirk_97
Regular Visitor

Calculate sales between two time values

Hi,

 

I'm trying to calculate the total sales per weekday, while some of the sales happen after 00:00:00. So, what I want is to manipulate the weekdays. Example: On tuesday 03:12:49 there is a sale, but I want to put that sale at the monday before.

 

The 'new days' I want to create begin at 10:00:00 AM and end at 09:59:59 AM the next weekday.

Then e.g. create 7 DAX formulas:

'Sales monday' =  
'Sales tuesday' =
etc.

 

Can you please help me?

1 ACCEPTED SOLUTION
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @Dirk_97 ,

 

I think I have an idea. I would recommend you to manipulate the data in Power Query like the following.

 

Lets assume I have a list of DateTime values.

Mikelytics_1-1667427188721.png

transform the data into decimal

Mikelytics_2-1667427260805.png

data are translated into decimals:

Mikelytics_5-1667427487057.png

 

 

Now you create a custom column. You want to shift by 10 Hours and a full 1 is like 1 day in date format. So I want to reduce the decimal value by 10/24 pieces.

Mikelytics_4-1667427453822.png

Now it looks like this

Mikelytics_9-1667427814896.png

 

 

After adding the custom column I transform the data back to date time

Mikelytics_7-1667427606685.png

 

result: in the new column all DateTime values are reduced by 10 hours. Now use the new column for all your calculations.

Mikelytics_8-1667427722274.png

 

Best regards

Michael

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your kudos.

 

@ me in replies or I'll lose your thread.

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

1 REPLY 1
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @Dirk_97 ,

 

I think I have an idea. I would recommend you to manipulate the data in Power Query like the following.

 

Lets assume I have a list of DateTime values.

Mikelytics_1-1667427188721.png

transform the data into decimal

Mikelytics_2-1667427260805.png

data are translated into decimals:

Mikelytics_5-1667427487057.png

 

 

Now you create a custom column. You want to shift by 10 Hours and a full 1 is like 1 day in date format. So I want to reduce the decimal value by 10/24 pieces.

Mikelytics_4-1667427453822.png

Now it looks like this

Mikelytics_9-1667427814896.png

 

 

After adding the custom column I transform the data back to date time

Mikelytics_7-1667427606685.png

 

result: in the new column all DateTime values are reduced by 10 hours. Now use the new column for all your calculations.

Mikelytics_8-1667427722274.png

 

Best regards

Michael

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your kudos.

 

@ me in replies or I'll lose your thread.

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.