Forum Discussion
Calculate average each month after a visit date
| Name | SELL | DATE | VISIT DATE |
| Alan | 5 | 2024-01 | |
| Alan | 10 | 2024-02 | 2024-02 |
| Alan | 15 | 2024-03 | |
| Alan | 20 | 2024-04 | |
| Alan | 25 | 2024-05 | |
| Alan | 30 | 2024-06 | |
| Alan | 40 | 2024-07 | |
| TED | 5 | 2024-01 | |
| TED | 20 | 2024-02 | |
| TED | 15 | 2024-03 | 2024-03 |
| TED | 20 | 2024-04 | |
| TED | 25 | 2024-05 | |
| TED | 30 | 2024-06 | |
| TED | 40 | 2024-07 |
Hi,
I would like to create a table with employee names in row and column each month/year above the "Visit Date" and in values the number of average sales month by month.
Exemple if i select 2024-05 in filter for alan, i see on the table 2024-03 /2024-04 / 2024-05 /2024-06 ( month after visit date) with the number of sells for each month and the average sell for each month too (15 for 2024-03), (15+20)/2 for 2024-04 and (15+20+25)/3 for 2024-05, etc...
Thank you
- Anonymous2 years ago
Hi psorel
Thanks for the reply from rajendraongole1.
psorel , the following is for your reference.
Create two measures as follow
Measure = VAR _visit = CALCULATE(MAX([VISIT DATE]), ALLEXCEPT('Table', 'Table'[Name])) RETURN IF(MAX([DATE]) > _visit, 1, 0)average = VAR _earlier = MAX([DATE]) RETURN AVERAGEX(FILTER(ALL('Table'), [Measure] = 1 && _earlier >= 'Table'[DATE] && 'Table'[Name] = MAX([Name])), [SELL])Output:
Best Regards,
Yulia XuIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- rajendraongole1
Super User
Hi psorel - create a cumulative sales starting from the "Visit Date.:
Cumulative Sales =CALCULATE(SUM('Vistis'[SELL]),FILTER(ALL('Vistis'),'Vistis'[Name] = MAX('Vistis'[Name]) &&'Vistis'[DATE] >= MINX(FILTER(ALL('Vistis'), 'Vistis'[Name] = MAX('Vistis'[Name]) && 'Vistis'[VISIT DATE] <> BLANK()), 'Vistis'[VISIT DATE]) &&'Vistis'[DATE] <= MAX('Vistis'[DATE])))This measure will calculate the number of months that have passed since the "Visit Date."Months Since Visit =DATEDIFF(MINX(FILTER(ALL('Vistis'), 'Vistis'[Name] = MAX('Vistis'[Name]) && 'Vistis'[VISIT DATE] <> BLANK()), 'Vistis'[VISIT DATE]),MAX('Vistis'[DATE]),MONTH) + 1This measure calculates the average sales for each month, starting from the "Visit Date."Average Sales =DIVIDE([Cumulative Sales], [Months Since Visit])Hope it helps.
- AnonymousNot applicable
Hi psorel
Thanks for the reply from rajendraongole1.
psorel , the following is for your reference.
Create two measures as follow
Measure = VAR _visit = CALCULATE(MAX([VISIT DATE]), ALLEXCEPT('Table', 'Table'[Name])) RETURN IF(MAX([DATE]) > _visit, 1, 0)average = VAR _earlier = MAX([DATE]) RETURN AVERAGEX(FILTER(ALL('Table'), [Measure] = 1 && _earlier >= 'Table'[DATE] && 'Table'[Name] = MAX([Name])), [SELL])Output:
Best Regards,
Yulia XuIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.