Forum Discussion
Dax for earliest date
Hi,
My requirement is, I have set of document numbers, thier sales amount, and thier posting date.
I need a measure for rolling 12 months value (for july 2023, I will consider july 2022 to july 2023 values) where the filter condition is , if a document number is repeated in that rolling 12 months , then I have to consider the first (earliest posting date in that 12 months period) date sales amount for calculation.
I am struck here with the following measure, where I am not able to implement the first date calculation
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")
5 Replies
- sharongHelper I
No, I am not getting the expected out, since i didnt include the first date calculation.
if a document number [Column name: doc_no] is repeated in that rolling 12 months , then I have to consider the first (earliest posting date in that 12 months period) date sales amount for calculation.Can you please help in adding this filter condition into the current dax, so that I can check if its returning the correct output. Or if there is any other way of writing this logic, let me know kindly
- sharongHelper I
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_bihCommunity 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")