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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Fill up or down based on conditions

Hello everyone,

 

I need to complete some blanks in a table based on an id_employee and an id_week. If the first registry (by id_week) of an employee is blank it should be filled up with the following category of this employee, in the case that the blank registry is the last one of an employee, it should be filled down with the previous category.


Here an example table of how it should look and the data table:

aguuzdo_0-1677880297520.png

 

id_employeeid_weekcategory
11 
12a
13a
14b
15 
23a
24b
25c
26 
32 
33b
34c
1 ACCEPTED SOLUTION
artemus
Microsoft Employee
Microsoft Employee

The easy (but ugly) way of doing this is to:

1. Create 3 index columns starting at 1,2,3

2. Do a self merge with index column 2 and index column 1 as the join columns

3. Do the same for index column 2 and index column 3.

4. Expand the join columns.

5. Rename the 2nd weekcategory column (the first join result) as "Prevweekcategory" similar for the id_employee

6.Rename the 2nd weekcategory column (the first join result) as "Nextweekcategory" similar for the id_employee

 

Now add a new column "Fixedweekcategory" with the logic to pick either the appropiate weekcategory based on if the current weekcategory is blank and if the current employee id matches the next or previous employee id.

View solution in original post

1 REPLY 1
artemus
Microsoft Employee
Microsoft Employee

The easy (but ugly) way of doing this is to:

1. Create 3 index columns starting at 1,2,3

2. Do a self merge with index column 2 and index column 1 as the join columns

3. Do the same for index column 2 and index column 3.

4. Expand the join columns.

5. Rename the 2nd weekcategory column (the first join result) as "Prevweekcategory" similar for the id_employee

6.Rename the 2nd weekcategory column (the first join result) as "Nextweekcategory" similar for the id_employee

 

Now add a new column "Fixedweekcategory" with the logic to pick either the appropiate weekcategory based on if the current weekcategory is blank and if the current employee id matches the next or previous employee id.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.