Forum Discussion
Count based on multiple criteria
- 7 years ago
Hi Yggdrasill
you can do thi sin 2 steps:
first add this column:
AddedCol1 = ISEMPTY( CALCULATETABLE( Data, ALLEXCEPT( Data, Data[ColumnB], Data[ColumnC] ), Data[Date] = EARLIER( Data[Date] ) - 1 ) ) + 0and then this final column:
AddedCol2 = IF( Data[AddedCol1] = 0, BLANK(), CALCULATE( SUM( Data[AddedCol1] ), ALLEXCEPT( Data, Data[ColumnC], Data[ColumnB] ), Data[Date] <= EARLIER( Data[Date] ) ) )
Going back to this problem.
I have defined a holiday table which is merged to my date table. I want to exclude holidays, saturdays and sundays from my counter but doesn't the function EARLIER() expect consecutive dates ?
Example of the output (Correct Calc count)
| ColumnA | Date | ColumnB | ColumnC | Calculate count | Correct Calc count | Day of week | ||
| 7 | 21.9.2017 | 1000 | A | 1 | 1 | 5 | ||
| 7 | 22.9.2017 | 1000 | A | 6 | ||||
| 7 | 16.11.2017 | 1000 | A | 2 | 2 | 5 | ||
| 7 | 17.11.2017 | 1000 | A | 6 | Friday | |||
| NEW LINE | 20.11.2017 | 1000 | A | 3 | 2 | Monday | ||
| 7 | 8.1.2018 | 1000 | A | 4 | 3 | 2 | ||
| 7 | 9.1.2018 | 1000 | A | 3 | ||||
| 7 | 12.1.2018 | 1000 | A | 5 | 4 | 6 | ||
| 7 | 1.6.2018 | 1000 | A | 6 | 5 | 6 | ||
| 7 | 3.10.2018 | 1000 | A | 7 | 6 | 4 | ||
| 7 | 4.10.2018 | 1000 | A | 5 | ||||
| 7 | 3.1.2019 | 1000 | A | 8 | 7 | 5 | ||
| 7 | 11.2.2019 | 1000 | A | 9 | 8 | 2 | ||
| 7 | 12.2.2019 | 1000 | A | 3 |
I tried to exclude the holidays and weekends from my calculations but I'm not getting the desired "correct" output
- LivioLanzo7 years agoSolution Sage
I think you just need to change the 'AddCol1' formula to:
AddedCol1 = var subDays = IF( Data[Day of Week] = 2, 3, 1 ) return ISEMPTY( CALCULATETABLE( Data, ALLEXCEPT( Data, Data[ColumnB], Data[ColumnC] ), Data[Date] = EARLIER( Data[Date] ) - subDays ) ) + 0- Yggdrasill7 years agoResponsive Resident
That could work well in case of mondays. However, I'm dealing with holidays too !
I have a Holiday table merged to my datetable so all holiday rows are marked with 0 and 1 if their active. I basically need to count the days between the last active day and current active day and use that variable for the subDays- LivioLanzo7 years agoSolution Sage