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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
chrisb182
Frequent Visitor

Sum of values between start/end date, where some end dates are 'null'

Good morning,

 

I am trying to sum values for various accounts which all have a start date, but only some have a terminated date.

 

For example, if I select my slicer to view sales for months January - May, I would expect:

- For an active account that has a start date of 01/02/2024 to sum their sales for February, March, April and May,

- For a terminated account that started on 01/03/24 but terminated on 30/04/24, to sum their sales for March and April only.

 

I have tried to use the DATESBETWEEN function (using 'Start Date' and 'Terminated Date') in conjunction with a SUM/CALCULATE formula, but the DAX keeps failing because (obviously) the live accounts don't have a date in the Terminated Date.

 

Does anyone know of a simple DAX that I can use? 

 

I hope that the above makes sense.

 

Cheers,

Chris

1 ACCEPTED SOLUTION

Hi @chrisb182 

Thank you for providing me with the workable data. There are mutiple ways to produce your required output and one of them is as follows.  I've written two dax formulas as shown below, one indicating the number of the open accounts at any given point in time (duration of counts), and another indicating the sum of the sales during the period accounts are open.  

The first measure expressing the count of accounts during the open period is as follows:

DataNinja777_0-1715960310381.png

The second measure shows the sales amount during the period account is open.  For this, nstead of the 2 conditions, the 3rd condition of the revenue recording date is within the account opening period is added to the 1st measure, and the sales amount, instead of the count of the account was sumxed over the table.

DataNinja777_1-1715960554448.png

The important thing for this data model to work as intended is to have the calendar table as a disconnected table from the fact table as shown in the data model below.  This is because there are multiple dates in the fact table, we should not relate the date fields to the calendar table for the data model to behave in the way we want with respect to the time dimension.  

DataNinja777_3-1715960634472.png

 

The resultant visualization of the two measures above is as follows:

DataNinja777_2-1715960587195.png

Please let me know if the above meets your expectations.  I attach an example pbix file below.

Best regards,

View solution in original post

5 REPLIES 5
chrisb182
Frequent Visitor

Hi @DataNinja777 

 

I cant get that formula to work unfortunately.

 

Here's some sample data as requested.

 

AccountSubGroup Start DateSubGroup Terminated DateSales DateSale Amt
L12/01/202308/02/202315/04/20233,718
W06/02/2023 15/04/20239,152
C30/04/202310/12/202317/04/2023777
X07/04/202322/03/202428/04/20232,012
J27/02/2023 05/05/20235,430
F12/03/202323/01/202406/05/20235,940
J27/02/2023 10/05/20239,783
S27/03/2023 12/05/20232,273
S27/03/2023 14/05/20237,152
Y15/04/202324/02/202421/05/20236,752
R29/03/2023 04/06/20234,296
X07/04/202322/03/202406/06/20236,819
A30/12/2023 12/06/2023541
W06/02/2023 12/06/20236,756
U07/01/2023 16/06/20233,463
F12/03/202323/01/202419/06/20237,023
V26/04/2023 22/06/20237,337
M13/04/2023 29/06/20232,104
X07/04/202322/03/202402/07/20238,680
Z02/03/202325/01/202408/07/202382
H10/02/2023 11/07/20239,676
I05/04/202306/01/202411/07/20234,958
E21/01/2023 12/07/20231,833
Y15/04/202324/02/202414/07/20235,116
C30/04/202310/12/202324/07/20234,137
Z02/03/202325/01/202425/07/20232,712
E21/01/2023 27/07/20235,509
M13/04/2023 27/07/20238,573
D31/01/202331/01/202431/07/20233,964
B27/03/2023 01/02/20243,588
W06/02/2023 03/02/20241,173
D31/01/202331/01/202412/02/20246,670
K28/04/202317/11/202313/02/20241,518
R29/03/2023 14/02/20248,942
U07/01/2023 14/02/20249,294
N06/04/2023 17/02/20246,753
Y15/04/202324/02/202418/02/20243,394
D31/01/202331/01/202419/02/20241,671
E21/01/2023 21/02/20245,863
R29/03/2023 24/02/20245,568
K28/04/202317/11/202325/02/20248,383
E21/01/2023 27/02/20242,099
L12/01/202308/02/202329/02/20248,260
E21/01/2023 01/03/20248,966
B27/03/2023 02/03/20242,393
F12/03/202323/01/202402/03/20242,586
O28/02/202302/05/202302/03/20242,844
Y15/04/202324/02/202409/03/20248,280
F12/03/202323/01/202414/03/20248,944
N06/04/2023 14/03/20243,972
R29/03/2023 16/03/20243,403
G20/03/202307/05/202323/03/20242,890
K28/04/202317/11/202323/03/20246,208
L12/01/202308/02/202325/03/20245,209
X07/04/202322/03/202425/03/20249,651
D31/01/202331/01/202426/03/20249,970
G20/03/202307/05/202307/04/2024614
G20/03/202307/05/202307/04/20245,448
J27/02/2023 12/04/2024257
X07/04/202322/03/202414/04/20245,333
V26/04/2023 15/04/20246,310
J27/02/2023 16/04/20247,539
O28/02/202302/05/202316/04/20242,331
S27/03/2023 17/04/20243,735
V26/04/2023 17/04/20245,748
C30/04/202310/12/202318/04/20247,276
Y15/04/202324/02/202418/04/20244,273
B27/03/2023 29/04/20244,575
T17/03/2023 29/04/20245,980
R29/03/2023 05/05/20247,724
J27/02/2023 08/05/20249,736
T17/03/2023 10/05/20242,879
N06/04/2023 13/05/20241,477
Z02/03/202325/01/202413/05/20247,068
E21/01/2023 16/05/20249,448
U07/01/2023 19/05/20242,905
A30/12/2023 22/05/20249,110
P27/01/2023 22/05/20242,950
S27/03/2023 25/05/20248,761
Q03/04/2023 26/05/20249,374
C30/04/202310/12/202329/05/20245,444

Hi @chrisb182 

Thank you for providing me with the workable data. There are mutiple ways to produce your required output and one of them is as follows.  I've written two dax formulas as shown below, one indicating the number of the open accounts at any given point in time (duration of counts), and another indicating the sum of the sales during the period accounts are open.  

The first measure expressing the count of accounts during the open period is as follows:

DataNinja777_0-1715960310381.png

The second measure shows the sales amount during the period account is open.  For this, nstead of the 2 conditions, the 3rd condition of the revenue recording date is within the account opening period is added to the 1st measure, and the sales amount, instead of the count of the account was sumxed over the table.

DataNinja777_1-1715960554448.png

The important thing for this data model to work as intended is to have the calendar table as a disconnected table from the fact table as shown in the data model below.  This is because there are multiple dates in the fact table, we should not relate the date fields to the calendar table for the data model to behave in the way we want with respect to the time dimension.  

DataNinja777_3-1715960634472.png

 

The resultant visualization of the two measures above is as follows:

DataNinja777_2-1715960587195.png

Please let me know if the above meets your expectations.  I attach an example pbix file below.

Best regards,

DataNinja777
Super User
Super User

Hi @chrisb182 ,

One general question which I have from reading your requirement above is how can a terminated account have sales after the termination, and also, how can an account not yet open have a sales, and from this reason of tautology, I thought whether it is open or not is a superfluous condition for adding up sales becuase all the accounts which have sales cannot be other than open account (not yet closed).  Is this assumption correct?  If not, please let me know in which cases closed accounts can have sales amounts in your specific business circumstances.  Regarding the accounts which are not yet closed and have blank values in the closed date field, I recommend to create another calculated column where closed dates are assumed to be like certain dates in the future like 6 months later, so that the calculation of the duration will show it as open as of the analysis dates by writing if formula, such as, if closed date is blank() then today()+30*6, otherwise, closed date.  Sorry for not using exact dax formula and writing in words, but I am assuming that you know what I meant.  

Best regards,

Hi @DataNinja777 

 

Thank you for your response.

 

Basically, the data I source has numerous accounts. Some of these accounts can join a separate group of accounts at any given time (lets call this SubGroup), so a start date is given to those accounts. Simarily, if those accounts want to opt-out of the SubGroup they are given a terminated date.

 

The problem with the source data is that I cannot just pull data for those accounts in the SubGroup - it has to be for all accounts.

 

For example, if I source data for the whole of 2023 there will be 150 out of 2000 accounts that joined this SubGroup at any given time during 2023, and I just need to collate their sales whilst part of this SubGroup during 2023.

 

That's probably as clear as mud, but I hope it makes some form of sense.

Hi @chrisb182 ,

Thanks for your explanation of your specific business circumstances.  I got the point.  In that case, what about writing a formula like below?  

DataNinja777_0-1715950480733.png

The key to getting the formula above to work is to have your calculated Calendar table as a disconnected table from your sales fact table.  

If I can have more sample field names and dummy data, I can prepare pbix file, but hopefully you can get started with the above.  

Best regards,

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors