Forum Discussion
Dax for earliest date
- 3 years ago
Hi sharong I created simple sum measure Total Sales and 3 calculated columns.
I manage to get your July 2023 data amount 750 but not for June 1074 as calculation of occurance is complex for single column and two more months. Hope this help
Total Sales =SUM ( Sheet1[sales amount] )Posting Date Within Last 12 Months =//calculation of posting date in range of datesVAR __MaxPostingDate = MAX('Sheet1'[posting date])VAR __Last12MonthsStart = __MaxPostingDate - 365RETURNIF('Sheet1'[posting date] >= __Last12MonthsStart&& 'Sheet1'[posting date] <= __MaxPostingDate,TRUE(), FALSE())Sequence by document =//sequence by document no and relevant posting dateVAR CurrentDate = Sheet1[posting date]RETURN COUNTROWS (FILTER (CALCULATETABLE (Sheet1,ALLEXCEPT ( Sheet1, Sheet1[document no] ),Sheet1[Posting Date Within Last 12 Months]=TRUE()),Sheet1[posting date] <= CurrentDate))Relevant or Not Relevant =IF(Sheet1[Posting Date Within Last 12 Months]=TRUE() && Sheet1[Sequence by document]=1,"Relevant","Not Relevant")
Hi sharong no data sufficient to provide some sound possible solution, so please check link below and adjust your table / data columns name (see first example). Hope this help
Hi Below is the sample data,
| document no | posting date | sales amount |
| 143 | 1st june 2022 | 89 |
| 156 | 4th june 2022 | 85 |
| 143 | 2nd july 2022 | 50 |
| 132 | 3rd aug 2022 | 100 |
| 156 | 5th sep 2022 | 600 |
| 132 | 5th dec 2022 | 800 |
| 143 | 1st july 2023 | 20 |
So in the calculation,
1) I take only rolling 12 months, for July 2023, [I will consider july 2022 to july 2023]
2) So first two rows will not be considered for calculation
3) And now in remaining rows, document 143 & 132 are repeated. In this case, we have to take the first occuring date for those document numbers.
for document 143, we consider , 2nd July 2022 sales value
for document no 132, we consider, 3rd august 2022 sales value
remaining document values will be same.
So my expected output is:
| Jun-23 | Jul-23 | |
| Rolling sales value | 1074 | 750 |
- some_bih3 years ago
Community Champion
Hi sharong I created simple sum measure Total Sales and 3 calculated columns.
I manage to get your July 2023 data amount 750 but not for June 1074 as calculation of occurance is complex for single column and two more months. Hope this help
Total Sales =SUM ( Sheet1[sales amount] )Posting Date Within Last 12 Months =//calculation of posting date in range of datesVAR __MaxPostingDate = MAX('Sheet1'[posting date])VAR __Last12MonthsStart = __MaxPostingDate - 365RETURNIF('Sheet1'[posting date] >= __Last12MonthsStart&& 'Sheet1'[posting date] <= __MaxPostingDate,TRUE(), FALSE())Sequence by document =//sequence by document no and relevant posting dateVAR CurrentDate = Sheet1[posting date]RETURN COUNTROWS (FILTER (CALCULATETABLE (Sheet1,ALLEXCEPT ( Sheet1, Sheet1[document no] ),Sheet1[Posting Date Within Last 12 Months]=TRUE()),Sheet1[posting date] <= CurrentDate))Relevant or Not Relevant =IF(Sheet1[Posting Date Within Last 12 Months]=TRUE() && Sheet1[Sequence by document]=1,"Relevant","Not Relevant")