Forum Discussion
Bradford factor Calculation
- 9 years ago
Thanks for that Simon.
Here is my suggested approach - uploaded with simplified data here:
https://www.dropbox.com/s/gt1jytqobrc9ilt/Bradford%20Factor.pbix?dl=0
- Add a Block Index column to your original table, so that Block Index has a different value for each block of consecutive days with the same value of Abs, across all ClockNos.
To do this, I carried out a series of steps in the Query Editor:- Sort the rows by ClockNo & Date
- Group the rows by ClockNo & Abs, using GroupKind.Local, which groups each consecutive block of ClockNo & Abs values.
- Add a Block Index column to the resulting grouped table.
- Re-expand the grouped rows, then tidy up.
- Create a Separate Absences measure, which is a DISTINCTCOUNT of Block Index where Abs="2".
- Create a Days Absent measure, which counts rows of the table where Abs="2".
- Create a Bradford Factor measure equal to [Separate Absences] ^ 2 * [Days Absent]
The measures in the end are:
Separate Absences = CALCULATE ( DISTINCTCOUNT ( 'Bradford Factor'[Block Index] ), 'Bradford Factor'[Abs] = "2" ) Days Absent = CALCULATE ( COUNTROWS ( 'Bradford Factor' ), 'Bradford Factor'[Abs] = "2" ) Bradford Factor = IF ( HASONEVALUE ( 'Bradford Factor'[ClockNo] ), // Only calculate for one ClockNo at a time, and don't aggregate ClockNos [Separate Absences] ^ 2 * [Days Absent] )Bradford Factor here doesn't aggregate ClockNos, but you could aggregate using AVERAGEX or some other method if you want.
Hopefully this does what you expect and can be applied to your data model.
Cheers,
Owen
- Add a Block Index column to your original table, so that Block Index has a different value for each block of consecutive days with the same value of Abs, across all ClockNos.
Thanks for that Simon.
Here is my suggested approach - uploaded with simplified data here:
https://www.dropbox.com/s/gt1jytqobrc9ilt/Bradford%20Factor.pbix?dl=0
- Add a Block Index column to your original table, so that Block Index has a different value for each block of consecutive days with the same value of Abs, across all ClockNos.
To do this, I carried out a series of steps in the Query Editor:- Sort the rows by ClockNo & Date
- Group the rows by ClockNo & Abs, using GroupKind.Local, which groups each consecutive block of ClockNo & Abs values.
- Add a Block Index column to the resulting grouped table.
- Re-expand the grouped rows, then tidy up.
- Create a Separate Absences measure, which is a DISTINCTCOUNT of Block Index where Abs="2".
- Create a Days Absent measure, which counts rows of the table where Abs="2".
- Create a Bradford Factor measure equal to [Separate Absences] ^ 2 * [Days Absent]
The measures in the end are:
Separate Absences =
CALCULATE (
DISTINCTCOUNT ( 'Bradford Factor'[Block Index] ),
'Bradford Factor'[Abs] = "2"
)
Days Absent =
CALCULATE (
COUNTROWS ( 'Bradford Factor' ),
'Bradford Factor'[Abs] = "2"
)
Bradford Factor =
IF (
HASONEVALUE ( 'Bradford Factor'[ClockNo] ),
// Only calculate for one ClockNo at a time, and don't aggregate ClockNos
[Separate Absences]
^ 2
* [Days Absent]
)Bradford Factor here doesn't aggregate ClockNos, but you could aggregate using AVERAGEX or some other method if you want.
Hopefully this does what you expect and can be applied to your data model.
Cheers,
Owen
Hello Owen.
I followed your instructions to the letter, but when I come to visualise the data it just shows a count of the number of absences.
I'm lost again.... have attached my saved file.
https://www.dropbox.com/s/wd2ifxpu0qaxl1h/post%20bradford%20factor.pbix?dl=0
I'm gonna keep trying with it, but again I'd appreciate your help
Cheers
Simon
- OwenAuger9 years agoSuper User
No worries Simon :smileyhappy:
The key part that was missing was, in the "Group By" step, you need to provide a fourth argument to the Table.Group function equal to GroupKind.Local. This ensures that contiguous blocks are treated as groups. This isn't an option in the "Group By' dialog box so you have to edit the code after creating that step. If you don't provide this argument, for example all the "2"s from one ClockNo are grouped together, regardless of whether they occurred in a contiguous block.
I would also suggest when you expand the grouped table, don't expand Abs and ClockNo (otherwise you end up with duplicate columns) and remove all the prefixes in the expanded column names.
Otherwise the measure definitions look fine :)
I've made those changes and reuploaded here
https://www.dropbox.com/s/t2po0u5qhgnl8sx/post%20bradford%20factor%20-%20Owen%20edit.pbix?dl=0
But I can't verify it works since I don't have access to your ODBC data source so the table can't update.
Please post back if it's not working or doesn't make sense.
Cheers,
Owen :)
- secure_1019 years agoFrequent Visitor
Thanks Owen
Thats worked perfect
You're an absolute Star, couldn't have done it without you.
Thanks again
Simon
- OwenAuger9 years agoSuper User
You're welcome Simon, glad to have helped :)
It was quite an interesting problem to look at - a little out of the ordinary which piqued my interest!
Cheers,
Owen