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

Sum of value from dinamic dates from two tables

Hello

I want to sum a total of real sales between dates contained on other table; however, with the formula below, I always get the total sales for all dates. 

 

Table 1  
Date of requestStimated Volume Order for the monthProduct
15/04/202050A
15/04/2020100A
15/04/202080B
25/04/2020100A
25/04/202040B
25/04/202050B
10/05/2020100A
10/05/2020200B
15/05/2020500A
15/05/2020300B

 

Table 2  
Date of saleReal salesProduct
01/04/202010A
02/04/20203B
03/04/20207A
04/04/202013B
05/04/20205A
06/04/20204B
07/04/202019A
08/04/202013B
09/04/20207A
10/04/202018B
11/04/202012A
12/04/202011B
13/04/202016A
14/04/20206B
15/04/202019A
16/04/20208B
17/04/20204A
18/04/202019B
19/04/202013A
20/04/20207B
21/04/202018A
22/04/202012B
23/04/202011A
24/04/202016B
25/04/20206A
26/04/202019B
27/04/20208A
28/04/20207B
29/04/202018A
30/04/202012B
01/05/202019A
02/05/20208B
03/05/20204A
04/05/202019B
05/05/202013A
06/05/20207B
07/05/202018B
08/05/202012A
09/05/202011B
10/05/20204A
11/05/202019B
12/05/202013A
13/05/20207B
14/05/202018B

 

Result desiredSales as of Date of Request for AprilSales as of Date of Request for AprilSales as of Date of Request for MaySales as of Date of Request for May
Vol Sales by product15/04/202025/04/202010/05/202015/05/2020
A95525213
B68626344
Total16311411557

 

measure = calculate(
var minDate = STARTOFMONTH(Table 1 [Date])
var maxDate = CALCULATE(Max(Table 1 [Date]),ALLSELECTED(Table 1 [Date]))

return
Calculate (
sum(Table 2[Real Sales]),Table 1 [Date]=maxDate))
 
ERRORSales as of Date of Request for AprilSales as of Date of Request for AprilSales as of Date of Request for MaySales as of Date of Request for May
Vol Sales by product15/04/202025/04/202010/05/202015/05/2020
A1471476565
B130130107107
Total277277172172

 

 

Thanks in advance for your help 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous  Guessing but seems like it should be something like:

measure =
var minDate = STARTOFMONTH(Table 1 [Date])
var maxDate = CALCULATE(Max(Table 1 [Date]),ALLSELECTED(Table 1 [Date]))

return
Calculate (
sum('Table 2'[Real Sales]),'Table 2'[Date]>=minDate && 'Table 2'[Date]<=maxDate))

 

I personally wouldn't use STARTOFMONTH as DATE(YEAR(MAX(['Table 1'[Date])),MONTH(MAX('Table 1'[Date])),1) is the same thing and I do not like TI functions at all.

 

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Would you please explain more about your desired output? Please try the following measure:

measure = calculate(
var minDate = STARTOFMONTH(Table 1 [Date])
var maxDate = Max(Table 1 [Date])

return
Calculate (
sum(Table 2[Real Sales]),Table 1 [Date]>=minDate && Table 1 [Date]<=maxDate)

 

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

 

Best Regards,

Dedmon Dai

 

Greg_Deckler
Super User
Super User

@Anonymous  Guessing but seems like it should be something like:

measure =
var minDate = STARTOFMONTH(Table 1 [Date])
var maxDate = CALCULATE(Max(Table 1 [Date]),ALLSELECTED(Table 1 [Date]))

return
Calculate (
sum('Table 2'[Real Sales]),'Table 2'[Date]>=minDate && 'Table 2'[Date]<=maxDate))

 

I personally wouldn't use STARTOFMONTH as DATE(YEAR(MAX(['Table 1'[Date])),MONTH(MAX('Table 1'[Date])),1) is the same thing and I do not like TI functions at all.

 

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.