Forum Discussion
DAX Calculation from Minimum Date to Total Sums causing headache
Hello,
I have a data set where I am trying to calculate an accounts spend during a time period. In order to calculate it I need to use a Min([Date]) which when summing or totalling, then takes the min date of every account. Below is my formula, the PeriodDate[PeriodStartDate] is a calculated column that takes the inital start date and creates a new date on the aniversary every year to track what is being spent annually.
CALCULATE(
| Account | PeriodStartDate | Initial Date | Period Amount |
| 1A | 9/1/2024 | 9/1/2022 | 100 |
| 2A | 6/1/2024 | 6/1/2020 | 200 |
| Total | 500 |
Below here is the data it is pulling from. The only 1A amount I would want to pull is the 10/1/2024.
| Account | Date | Amount |
| 1A | 7/1/2024 | 100 |
| 1A | 8/1/2024 | 100 |
| 1A | 10/1/2024 | 100 |
| 2A | 7/1/2024 | 100 |
| 2A | 8/1/2024 | 100 |
| Total | 500 |
Any help or tips would be greatly appreciated!
Thank you!!
- Anonymous1 year ago
Hi WimpeyRoss ,
Based on the description, creating the calculated column periodStartDate.
PeriodStartDate = CALCULATE(MIN(PeriodDate[Date]), ALLEXCEPT(PeriodDate, PeriodDate[Account]))Then, try using the following DAX formula to calculate the account spend during a time period.
Period Amount = SUMX ( VALUES (PeriodDate[Account]), CALCULATE ( SUM (PeriodDate[Amount]), DATESINPERIOD ( dimdate[DATE], MIN (PeriodDate[PeriodStartDate]), TODAY() - MIN (PeriodDate[PeriodStartDate]), DAY ) ) )The result is shown below.
Best Regards,
Wisdom Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- Bibiano_Geraldo
Super User
Hi WimpeyRoss ,
Please try the bellow DAX and let me know if its all ok:
Period Amount = SUMX( SUMMARIZE( 'YourTable', 'YourTable'[Account], "AccountPeriodAmount", CALCULATE( SUM('YourTable'[Amount]), DATESINPERIOD( dimdate[DATE], MIN(PeriodDate[PeriodStartDate]), TODAY() - MIN(PeriodDate[PeriodStartDate]), DAY ) ) ), [AccountPeriodAmount] ) - AnonymousNot applicable
Hi WimpeyRoss ,
Based on the description, creating the calculated column periodStartDate.
PeriodStartDate = CALCULATE(MIN(PeriodDate[Date]), ALLEXCEPT(PeriodDate, PeriodDate[Account]))Then, try using the following DAX formula to calculate the account spend during a time period.
Period Amount = SUMX ( VALUES (PeriodDate[Account]), CALCULATE ( SUM (PeriodDate[Amount]), DATESINPERIOD ( dimdate[DATE], MIN (PeriodDate[PeriodStartDate]), TODAY() - MIN (PeriodDate[PeriodStartDate]), DAY ) ) )The result is shown below.
Best Regards,
Wisdom Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.