Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hello all,
I'm stuck with some calculation and I could use some help.
Here's what I'm trying to do : I have a production table with all my production orders and I would like to calculate the average duration between campaign for each specific group of product (then I'll be able to calculate the stock recommandation based on the average lenght of replenishment).
Here's an example of my dataset :
Product | Date | Product Group |
BB | 05-09-18 | Group B |
BB | 06-09-18 | Group B |
AA | 13-09-18 | Group A |
BB | 22-09-18 | Group B |
AA | 29-09-18 | Group A |
BB | 01-10-18 | Group B |
BA | 01-10-18 | Group B |
BB | 11-10-18 | Group B |
AA | 15-10-18 | Group A |
AC | 16-10-18 | Group A |
AA | 20-10-18 | Group A |
AC | 21-10-18 | Group A |
BB | 24-10-18 | Group B |
BA | 26-10-18 | Group B |
AA | 01-11-18 | Group A |
AA | 03-11-18 | Group A |
AC | 03-11-18 | Group A |
AB | 04-11-18 | Group A |
AA | 04-11-18 | Group A |
AA | 05-11-18 | Group A |
AA | 09-11-18 | Group A |
AA | 11-11-18 | Group A |
BB | 20-11-18 | Group B |
AA | 06-12-18 | Group A |
BB | 07-12-18 | Group B |
AB | 08-12-18 | Group A |
AC | 09-12-18 | Group A |
AA | 09-12-18 | Group A |
BB | 11-12-18 | Group B |
BA | 14-12-18 | Group B |
AC | 23-12-18 | Group A |
AA | 05-01-19 | Group A |
AA | 06-01-19 | Group A |
BB | 08-01-19 | Group B |
BB | 08-01-19 | Group B |
AA | 22-01-19 | Group A |
BB | 23-01-19 | Group B |
BA | 24-01-19 | Group B |
BB | 24-01-19 | Group B |
AA | 06-02-19 | Group A |
AA | 07-02-19 | Group A |
BB | 12-02-19 | Group B |
BB | 22-02-19 | Group B |
BB | 26-02-19 | Group B |
AA | 11-03-19 | Group A |
AC | 11-03-19 | Group A |
BB | 12-03-19 | Group B |
BB | 18-03-19 | Group B |
BA | 22-03-19 | Group B |
CA | 09-02-19 | Group C |
CB | 10-12-18 | Group C |
CC | 24-10-18 | Group C |
CB | 11-09-18 | Group C |
CC | 11-09-18 | Group C |
CC | 13-08-18 | Group C |
CB | 05-07-18 | Group C |
CB | 21-04-18 | Group C |
CB | 26-01-18 | Group C |
CA | 11-09-18 | Group C |
CA | 05-07-18 | Group C |
CA | 21-04-18 | Group C |
CA | 16-01-18 | Group C |
CA | 26-01-18 | Group C |
CC | 22-05-18 | Group C |
CC | 05-07-18 | Group C |
CC | 21-04-18 | Group C |
CC | 17-01-18 | Group C |
CC | 25-01-18 | Group C |
What I would like to calculate is first the difference between two campaign then the average duration between campaign for each Product Group.
From a previous thread I found the following formula for a calculated table :
DaysBetween = DATEDIFF ( 'Table'[date], FIRSTDATE ( FILTER ( ALL ( 'Table'[DATE] ), 'Table'[DATE] > EARLIER ( 'Table'[DATE] ) ) ), DAY )
Solved! Go to Solution.
Ok thank you for your reply, I manage to get the measure I expected from that topic.
So the first calculated column gives me the date of the last production for each product group row :
Date_Previous_Campaign = MAXX ( TOPN ( 1; FILTER ( TABLE; TABLE[Product Group] = EARLIER ( TABLE[Product Group] ) && TABLE[DATE] < EARLIER ( TABLE[DATE] ) ); TABLE[DATE]; DESC ); TABLE[DATE] )
Then I create a second calculated column to calculate the duration between two production orders :
Days since last campaign = DATEDIFF(TABLE[Date_Previous_Campaign];TABLE[DATE];DAY)
Then eventually my measure of average, excluding values under 3 days to really focus on campaign :
Average Duration = CALCULATE(AVERAGE(TABLE[Days since last campaign]);TABLE[Days since last campaign]>3)
Thanks for your answer, I got the result I expected. However it might not be the most optimized solution.
Have a good day !
@Anonymous ,
You may check if the post below helps.
Ok thank you for your reply, I manage to get the measure I expected from that topic.
So the first calculated column gives me the date of the last production for each product group row :
Date_Previous_Campaign = MAXX ( TOPN ( 1; FILTER ( TABLE; TABLE[Product Group] = EARLIER ( TABLE[Product Group] ) && TABLE[DATE] < EARLIER ( TABLE[DATE] ) ); TABLE[DATE]; DESC ); TABLE[DATE] )
Then I create a second calculated column to calculate the duration between two production orders :
Days since last campaign = DATEDIFF(TABLE[Date_Previous_Campaign];TABLE[DATE];DAY)
Then eventually my measure of average, excluding values under 3 days to really focus on campaign :
Average Duration = CALCULATE(AVERAGE(TABLE[Days since last campaign]);TABLE[Days since last campaign]>3)
Thanks for your answer, I got the result I expected. However it might not be the most optimized solution.
Have a good day !
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
63 |
User | Count |
---|---|
135 | |
126 | |
110 | |
70 | |
61 |