Forum Discussion
sunny18pc
2 years agoRegular Visitor
Power Bi Attendance Calculation (mom wise)
Hi All, Please help me calculate the attendance in power bi, Joing Date= when a employee joins the company LWD=when a employoess leaves Active Stage=Active/Inactive, Active=employee is s...
jennratten
2 years agoSuper User
Hello sunny18pc - it would be much better to do this kind of calculation with a DAX measure instead of Power Query. I have outlined the steps below and have also attached a sample pbix for you.
- Load your table into the data model
- add a date table (DAX calculated table)
- Create two relationships between your data table and the Date table (one on the Joining Date and another on the LWD date).
- Create a measure to return the number of employees that were active between the selected start and end date.
- Add a matrix visual to see the results.
sunny18pc
2 years agoRegular Visitor
Hi jennratten,
Thanks for you inputs,
Here is the sample for your reference:
I need the attendance for both active and inactive employee, However for active employees LWD= todays date
| Emp id | Joining | Active Stage | LWD | Dec-22 | Jan-23 | Feb-23 | Mar-23 | Apr-23 | May-23 | Jun-23 | Jul-23 | Aug-23 | Sep-23 | Oct-23 | Nov-23 |
| 102289903 | 25-Jul-23 | Inactive | 27-Sep-23 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | 31 | 27 | 0 | 0 |
| 102290552 | 25-Jul-23 | Inactive | 26-Jun-24 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | 31 | 30 | 31 | 30 |
| 102289725 | 25-Jul-23 | Inactive | 13-Mar-24 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | 31 | 30 | 31 | 30 |
| 102290822 | 25-Jul-23 | Inactive | 03-Aug-23 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | 3 | 0 | 0 | 0 |
| 102166787 | 05-Dec-22 | Inactive | 02-Jul-23 | 27 | 31 | 28 | 31 | 30 | 31 | 30 | 2 | 0 | 0 | 0 | 0 |
| 102166769 | 05-Dec-22 | Inactive | 05-Dec-23 | 27 | 31 | 28 | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 |
| 102166177 | 05-Dec-22 | Inactive | 05-Dec-23 | 27 | 31 | 28 | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 |
| 102166774 | 05-Dec-22 | Inactive | 01-Apr-23 | 27 | 31 | 28 | 31 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 102291568 | 26-Jul-23 | Inactive | 03-Feb-24 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 31 | 30 | 31 | 30 |
| 102257086 | 26-Jul-23 | Inactive | 01-Dec-23 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 31 | 30 | 31 | 30 |
| 102291686 | 26-Jul-23 | Inactive | 20-Nov-23 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 31 | 30 | 31 | 20 |
| 102291688 | 26-Jul-23 | Inactive | 06-Sep-23 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 31 | 6 | 0 | 0 |
| 102293911 | 26-Jul-23 | Inactive | 01-Feb-24 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 31 | 30 | 31 | 30 |
| 102294405 | 26-Jul-23 | Inactive | 05-Dec-23 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 31 | 30 | 31 | 30 |
| 102166171 | 05-Dec-22 | Inactive | 01-Feb-23 | 27 | 31 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 102291707 | 26-Jul-23 | Inactive | 12-Jun-24 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 31 | 30 | 31 | 30 |
| 102298741 | 14-Aug-23 | Inactive | 01-Dec-23 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 18 | 30 | 31 | 30 |
| 102166136 | 05-Dec-22 | Inactive | 05-Dec-23 | 27 | 31 | 28 | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 |
| 102303403 | 14-Aug-23 | Inactive | 09-Dec-23 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 18 | 30 | 31 | 30 |
| 102166157 | 05-Dec-22 | Inactive | 05-Dec-23 | 27 | 31 | 28 | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 |
| 102303164 | 14-Aug-23 | Inactive | 04-Jun-24 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 18 | 30 | 31 | 30 |
| 102303884 | 14-Aug-23 | Inactive | 20-Jun-24 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 18 | 30 | 31 | 30 |
| 102166772 | 05-Dec-22 | Inactive | 05-Dec-23 | 27 | 31 | 28 | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 |
| 102303131 | 14-Aug-23 | Inactive | 26-May-24 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 18 | 30 | 31 | 30 |
| 102166191 | 05-Dec-22 | Inactive | 05-Dec-23 | 27 | 31 | 28 | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 |
| 102166793 | 05-Dec-22 | Inactive | 05-Dec-23 | 27 | 31 | 28 | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 |
| 102166786 | 05-Dec-22 | Inactive | 05-Dec-23 | 27 | 31 | 28 | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 |
| 102166229 | 05-Dec-22 | Inactive | 05-Dec-23 | 27 | 31 | 28 | 31 | 30 | 31 | 30 | 31 | 31 | 30 | 31 | 30 |
| 102225372 | 26-Jul-23 | Active | - | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 31 | 30 | 31 | 30 |
| 102291622 | 26-Jul-23 | Active | - | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 31 | 30 | 31 | 30 |
| 102291806 | 26-Jul-23 | Active | - | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 6 | 31 | 30 | 31 | 30 |
- jennratten2 years agoSuper User
You can easily accommodate this by replacing the LWD value for active employees with today's date.
The script for the Employees table in Power Query becomes this (go to the Advanced Editor and replace the contents with the script below):
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUfLMS0wuySxLBTLN9Y1M9Y0MjIyBbEt9I3MIO1YnWskJVaGhkT5YoRFEE0KdM1DAEa5K3xCsygTIVoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, #"Active Stage" = _t, Joining = _t, LWD = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", type text}, {"Joining", type date}, {"LWD", type date}}), #"Replaced Value" = Table.ReplaceValue(#"Changed Type",null,Date.From ( DateTime.FixedLocalNow() ),Replacer.ReplaceValue,{"LWD"}) in #"Replaced Value"Result