Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Birdjo
Resolver II
Resolver II

Absence Period Calculation

Hello,

I am trying to figure out a way to visualize the period in which an employee was on a leave.

I am trying to do this without doing changes to the dataset I have.

Here is an example of the dataset:


As you can see in the first column I have the month, then employee, while to numerated columns represent the day of a month.
New months are generated by duplicating the employees. 


And the desired output would be something like this but in Power BI table:

 

Does anyone has any ideas how I can achieves the output I want the dataset structure I have?

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @Birdjo,

 

In your scenario, you can open the Query Editor in Power BI desktop:

 

1. Select the column Month, click Split Column.

z1.PNG

2. Select columns 1,2,..,7 at the same time, click UnPivot Columns.

3. Add a custom column to combine Year, Month and Day to a date column.

4. Filter to remain Leave values.

5. Use Group By like below:

 

z2.PNG

 

For detail steps, please check attached .pbix file.

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-qiuyu-msft
Community Support
Community Support

Hi @Birdjo,

 

In your scenario, you can open the Query Editor in Power BI desktop:

 

1. Select the column Month, click Split Column.

z1.PNG

2. Select columns 1,2,..,7 at the same time, click UnPivot Columns.

3. Add a custom column to combine Year, Month and Day to a date column.

4. Filter to remain Leave values.

5. Use Group By like below:

 

z2.PNG

 

For detail steps, please check attached .pbix file.

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
austinsense
Impactful Individual
Impactful Individual

My advice - keep the dataset just like it is BUT change the shape of it when you import it into the model.  Right now the data isn't tidy - all those columns with dates should be in one columns. It's easy to fix.

 

In the query select the first two columns, click on the header, and select "unpivot other columns" - After that you should have four columns Month, Employee, DayOfMonth, Value (once you've renamed the last two).

 

Then if you want to just see it by month, instead of day, then you can use GROUP BY - you don't have to do this because it's really better to keep it at the lowest level of granularity.

 

Ok that's the dataset, for the report you need to create a absence start & absence end measure - you can create a measure using MAX and MIN.

 

Hope this helps.

Austin is VP Operations at PowerPivotPro and a professional self-service enthusiast 🙂

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.