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
kyleb350
Helper I
Helper I

Calculating Daily Sales From Time Window

I am tasked to see if I can calculate past sales totals from when sales orders were in open status. The challenge is that all these orders are obviously closed, but I do have two dates on the orders that serve as a time window of when the order was open. Can I populate a date/calendar table (call it DailyOpenSales) where I can go through all orders and accumulate sales by day? 

 

SalesOrderHeader

OrderNo

DateCreated

InvoicedDate

1

|

*

Sales Order Detail

OrderNo

ItemCode

Amount

 

The logic to populate the daily sales would be something along the lines:

if SalesOrderHeader.DateCreated <= DailyOpenSales.Date && DailyOpenSales.Date < SalesOrderHeader.InvoicedDate,

DailyOpenSales.Sales += SalesOrderDetail.Amount

 

This sounds very resource intensive to go through all order lines for each day, but I can't think of any other way.

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @kyleb350 ,

According to your description, I create a sample.

This is SalesOrderHeader table.

vkalyjmsft_0-1646818800115.png

This is Sales Order Detail table. There are relationship between this table and SalesOrderHeader table.

vkalyjmsft_1-1646818843719.png

This is DailyOpenSales table.

vkalyjmsft_2-1646818938479.png

There are two open days in the sample, for the first open day 3/4/2021, there are two orders compliant with computing standards, they are 0002 and 0003.

For the second open day 5/4/2021, there are three orders compliant with computing standards, they are 0003, 0004 and 0005.

You can see the order 0003 compliant with two open days at the same time, to avoid double counting, I let it count on the smallest open date 3/4/2021.

Here's my solution.

1. Create a calculated column in the SalesOrderHeader table.

Amount Column = RELATED('Sales Order Detail'[Amount])

2. Create a calculated column in the DailyOpenSales table.

Rank = RANKX('DailyOpenSales','DailyOpenSales'[Date],,ASC,Dense)

3. Create another calculated column in the DailyOpenSales table.

Total Sales = 
SUMX (
    FILTER (
        ALL ( 'SalesOrderHeader' ),
        'SalesOrderHeader'[DateCreated] <= 'DailyOpenSales'[Date]
            && 'SalesOrderHeader'[InvoicedDate] > 'DailyOpenSales'[Date]
            && 'SalesOrderHeader'[DateCreated]
                > MAXX (
                    FILTER (
                        ALL ( 'DailyOpenSales' ),
                        'DailyOpenSales'[Rank]
                            = EARLIER ( 'DailyOpenSales'[Rank] ) - 1
                    ),
                    'DailyOpenSales'[Date]
                )
    ),
    'SalesOrderHeader'[Amount Column]
) * 'DailyOpenSales'[Sales]

Get the correct result.

vkalyjmsft_3-1646819509333.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

View solution in original post

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @kyleb350 ,

According to your description, I create a sample.

This is SalesOrderHeader table.

vkalyjmsft_0-1646818800115.png

This is Sales Order Detail table. There are relationship between this table and SalesOrderHeader table.

vkalyjmsft_1-1646818843719.png

This is DailyOpenSales table.

vkalyjmsft_2-1646818938479.png

There are two open days in the sample, for the first open day 3/4/2021, there are two orders compliant with computing standards, they are 0002 and 0003.

For the second open day 5/4/2021, there are three orders compliant with computing standards, they are 0003, 0004 and 0005.

You can see the order 0003 compliant with two open days at the same time, to avoid double counting, I let it count on the smallest open date 3/4/2021.

Here's my solution.

1. Create a calculated column in the SalesOrderHeader table.

Amount Column = RELATED('Sales Order Detail'[Amount])

2. Create a calculated column in the DailyOpenSales table.

Rank = RANKX('DailyOpenSales','DailyOpenSales'[Date],,ASC,Dense)

3. Create another calculated column in the DailyOpenSales table.

Total Sales = 
SUMX (
    FILTER (
        ALL ( 'SalesOrderHeader' ),
        'SalesOrderHeader'[DateCreated] <= 'DailyOpenSales'[Date]
            && 'SalesOrderHeader'[InvoicedDate] > 'DailyOpenSales'[Date]
            && 'SalesOrderHeader'[DateCreated]
                > MAXX (
                    FILTER (
                        ALL ( 'DailyOpenSales' ),
                        'DailyOpenSales'[Rank]
                            = EARLIER ( 'DailyOpenSales'[Rank] ) - 1
                    ),
                    'DailyOpenSales'[Date]
                )
    ),
    'SalesOrderHeader'[Amount Column]
) * 'DailyOpenSales'[Sales]

Get the correct result.

vkalyjmsft_3-1646819509333.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

littlemojopuppy
Community Champion
Community Champion

Hi @kyleb350 can you provide some sample data to work with?

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.