Forum Discussion
Calculating min, max and average time between two occurances
- 7 years ago
Hi gustavo_acqio ,
Firstly, create columns Group rank, DateDiff to get days between two accident date for each store.
Group rank = RANKX(FILTER(Table1,Table1[Store]=EARLIER(Table1[Store])),Table1[Date],,ASC,Dense)
DateDiff =
var pdate= CALCULATE(MAX(Table1[Date]),FILTER(Table1,Table1[Store]=EARLIER(Table1[Store])&&Table1[Group rank]=EARLIER(Table1[Group rank])-1))
return
DATEDIFF(pdate,Table1[Date],DAY)
Then, create columns to get min, max and average time between two occurances for each store.
Min_days = CALCULATE(MIN(Table1[DateDiff]),FILTER(ALLSELECTED(Table1),Table1[Store]=EARLIER(Table1[Store])))
Max_days = CALCULATE( MAX(Table1[DateDiff]),FILTER(ALLSELECTED(Table1),Table1[Store]=EARLIER(Table1[Store])))
Avg_days = CALCULATE( AVERAGE(Table1[DateDiff]),FILTER(ALLSELECTED(Table1),Table1[Store]=EARLIER(Table1[Store])))
When make some selections in slicer, return result showing picture below.
Here is my test pbix: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EaABQf0lJCZKssZatFErw_gBo6wAFMnFtIfPUp-EYeU-ww?e=M6JkPk
Best Regards,
Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi gustavo_acqio ,
Firstly, create columns Group rank, DateDiff to get days between two accident date for each store.
Group rank = RANKX(FILTER(Table1,Table1[Store]=EARLIER(Table1[Store])),Table1[Date],,ASC,Dense)
DateDiff =
var pdate= CALCULATE(MAX(Table1[Date]),FILTER(Table1,Table1[Store]=EARLIER(Table1[Store])&&Table1[Group rank]=EARLIER(Table1[Group rank])-1))
return
DATEDIFF(pdate,Table1[Date],DAY)
Then, create columns to get min, max and average time between two occurances for each store.
Min_days = CALCULATE(MIN(Table1[DateDiff]),FILTER(ALLSELECTED(Table1),Table1[Store]=EARLIER(Table1[Store])))
Max_days = CALCULATE( MAX(Table1[DateDiff]),FILTER(ALLSELECTED(Table1),Table1[Store]=EARLIER(Table1[Store])))
Avg_days = CALCULATE( AVERAGE(Table1[DateDiff]),FILTER(ALLSELECTED(Table1),Table1[Store]=EARLIER(Table1[Store])))
When make some selections in slicer, return result showing picture below.
Here is my test pbix: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EaABQf0lJCZKssZatFErw_gBo6wAFMnFtIfPUp-EYeU-ww?e=M6JkPk
Best Regards,
Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.