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

Get Start and End Dates for DATESBETWEEN from Another Table

Hi Everyone, 

 

I'm trying to make a measure that checks if a customer's sales records tally with their actual purchases from the supplier for a specific period.  Currently, I have 2 separate tables: one representing the customer's sales records and another for the record of their actual purchases from the supplier.

 

The result that I need for the measure based on the sample data below is 213K from Table 1 less 116K from Table 2 = 97K variance

***Please note that the actual tables contain data for several other customers and product types

 

Table 1: Customer's Sales Record for Product Soda A

 

The specific dates here represent instances where the supplier went to the customer to spot-check sales at that specific point in time.  This means that for the red-highlighted date/row, the customer sold 213K worth of product Soda A from December 15, 2020 (the day after the last visit date) to March 4, 2021.

 

CustomerDate of VisitSalesProduct
AWednesday, August 29, 2018282,581.38Soda A
ASunday, February 3, 2019856,529.54Soda A
AMonday, October 21, 20191,320,023.40Soda A
AWednesday, January 22, 2020507,254.76Soda A
AWednesday, September 9, 2020702,588.79Soda A
AMonday, December 14, 2020265,926.59Soda A
AThursday, March 4, 2021213,139.60Soda A

 

Table 2: Supplier's Records

 

These are the actual orders/purchases of the customer from the supplier.  Based on the previous table, if we want to check the 213K amount, we need to add all orders from the Dec. 15-Mar 4 period, which in this table are the highlighted rows whose orders total 116,000.

 

DateActual OrdersCustomerProduct
Thursday, November 19, 202016000ASoda A
Sunday, December 6, 202016000ASoda A
Thursday, December 17, 202016000ASoda A
Saturday, January 9, 202116000ASoda A
Friday, January 22, 202120000ASoda A
Sunday, January 31, 202116000ASoda A
Saturday, February 6, 202116000ASoda A
Sunday, February 14, 202116000ASoda A
Thursday, February 25, 202116000ASoda A
Tuesday, March 9, 202116000ASoda A
Wednesday, March 24, 202116000ASoda A
Monday, April 5, 202116000ASoda A

 

Thank you very much for any assistance 🙂

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

Hi @atacuboy ,

Please correct me if I wrongly understood your question.

You said when you choose Thursday, March 4, 2021 in 'Customer's Sales Record for Product Soda A' , the date from table 'Supplier's Records' must between December 15, 2020 (the day after the last visit date) to March 4, 2021 from table 'Customer's Sales Record for Product Soda A' .

(1)So I create a slicer use 'Customer''s Sales Record for Product Soda A'[Date of Visit] field . Through the slicer to filter the date from table 'Supplier'’s Records' between 'Customer's Sales Record for Product Soda A' [Date of visit] && 'Customer's Sales Record for Product Soda A' [last date of visit] .

last date of visit = CALCULATE(MAX('Customer''s Sales Record for Product Soda A'[Date of Visit]),FILTER('Customer''s Sales Record for Product Soda A','Customer''s Sales Record for Product Soda A'[Date of Visit]<EARLIER('Customer''s Sales Record for Product Soda A'[Date of Visit])))

Ailsa-msft_0-1618970796030.png

(2)Then create a column to sum the 'Supplier''s Records'[Actual Orders].

sum of actual orders = CALCULATE(SUM('Supplier''s Records'[Actual Orders]),FILTER('Supplier''s Records','Supplier''s Records'[Date]>'Customer''s Sales Record for Product Soda A'[last date of visit] && 'Supplier''s Records'[Date]<'Customer''s Sales Record for Product Soda A'[Date of Visit]))

Ailsa-msft_1-1618970796032.png

(3)calculate the Sales variance between two tables .

diff = 'Customer''s Sales Record for Product Soda A'[Sales]-'Customer''s Sales Record for Product Soda A'[sum of actual orders]

Ailsa-msft_2-1618970796034.png

I have attached the pbix file, you can refer to it.

Best Regards

Community Support Team _ Ailsa Tao

 

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

3 REPLIES 3
v-yetao1-msft
Community Support
Community Support

Hi @atacuboy ,

Please correct me if I wrongly understood your question.

You said when you choose Thursday, March 4, 2021 in 'Customer's Sales Record for Product Soda A' , the date from table 'Supplier's Records' must between December 15, 2020 (the day after the last visit date) to March 4, 2021 from table 'Customer's Sales Record for Product Soda A' .

(1)So I create a slicer use 'Customer''s Sales Record for Product Soda A'[Date of Visit] field . Through the slicer to filter the date from table 'Supplier'’s Records' between 'Customer's Sales Record for Product Soda A' [Date of visit] && 'Customer's Sales Record for Product Soda A' [last date of visit] .

last date of visit = CALCULATE(MAX('Customer''s Sales Record for Product Soda A'[Date of Visit]),FILTER('Customer''s Sales Record for Product Soda A','Customer''s Sales Record for Product Soda A'[Date of Visit]<EARLIER('Customer''s Sales Record for Product Soda A'[Date of Visit])))

Ailsa-msft_0-1618970796030.png

(2)Then create a column to sum the 'Supplier''s Records'[Actual Orders].

sum of actual orders = CALCULATE(SUM('Supplier''s Records'[Actual Orders]),FILTER('Supplier''s Records','Supplier''s Records'[Date]>'Customer''s Sales Record for Product Soda A'[last date of visit] && 'Supplier''s Records'[Date]<'Customer''s Sales Record for Product Soda A'[Date of Visit]))

Ailsa-msft_1-1618970796032.png

(3)calculate the Sales variance between two tables .

diff = 'Customer''s Sales Record for Product Soda A'[Sales]-'Customer''s Sales Record for Product Soda A'[sum of actual orders]

Ailsa-msft_2-1618970796034.png

I have attached the pbix file, you can refer to it.

Best Regards

Community Support Team _ Ailsa Tao

 

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

Thank you very much for the help, I really appreciate it! It works! 🙂

atacuboy
Frequent Visitor

Forgot to add, what I currently have is 

Customer Orders = calculate(sum('Table 2'[Actual Orders]),DATESBETWEEN('Table 1'[Date of Visit],[Start Date],[End Date]))
 
Datesbetween not working yet as it seems I can't use dates from another table
 
No start and end dates 

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.