Forum Discussion
Pivot Table with Multiple Dates
Hello guys...hoping you can help me here.
I want to create a pivot table where I can see at once the current number of man-days the worker has consumed. The workers are on-call, hence there are so many arrivals and departures.
Example.
NAME ARRIVAL DATE DEPARTURE DATE STATUS MAN-DAYS
Worker 1 Jan. 15, 2023 March 15, 2023 Inactive 40
Worker 1 April 1, 2023 May 31, 2023 Inactive 20
Worker 1 June 15, 2023 Active 70
Worker 2 Jan. 20, 2023 Active 100
Worker 3 Jan. 20, 2023 Jan. 31, 2023 Inactive 5
When I created the Pivot table, it shows like this.
NAME Min. of ARRIVAL DATE Max of DEPARTURE DATE STATUS Sum of MAN-DAYS
Worker 1 Jan. 15, 2023 May 31, 2023 Inactive 60
June 15, 2023 Jan. 0, 1990 Active 70
Worker 2 Jan. 20, 2023 Jan. 0, 1990 Active 100
Worker 3 Jan. 20, 2023 Jan. 31, 2023 Inactive 5
Since Worker 1 has 2 Status on record, his name has 2 lines also. I want to have one line only showing the latest Status.
Worker 1 Jan. 15, 2023 Active 130
Jan. 0, 1990 is a result because the cell is blank as the Worker is still active. No departure date yet. How to make it blank as well.
Thank you all.
Creating PivotTable add data to data model
Add Name to Rows.
In PivotTable pane right click on table name and Add measure
add measures one by one
Finalize PivotTable with them
- peiyezhuBronze Contributor
latest status 2023/6/15?
Worker 1 2023/6/15 Active 130 Worker 2 2023/1/20 Active 100 Worker 3 2023/1/20 2023/1/31 Inactive 5 create temp table aa as
select f01,f02,f03,f04,sum(f05) total,max(f02) m from showing_the_latest_Status group by f01;
cli_no_header;
select colExclude[m] from aa; Depends on your Excel platform/version. Creating PivotTable you may add data to data model, add DAX measures like
Arrival:=MIN( daysConsumed[ARRIVAL DATE] ) Departure:=IF( "Active" IN VALUES(daysConsumed[STATUS]), BLANK(), MAX(daysConsumed[DEPARTURE DATE]) ) ManDays:=SUM( daysConsumed[MAN-DAYS] ) Current Status:=IF( "Active" IN VALUES(daysConsumed[STATUS]), "Active", "Inactive" )
and use them creating PivotTable
- DeejayJohnCopper Contributor
Thanks Sergei.
This is the output I want to have.
But I don't know how to use your formula.I am using Excel 365.
Creating PivotTable add data to data model
Add Name to Rows.
In PivotTable pane right click on table name and Add measure
add measures one by one
Finalize PivotTable with them
- LeonPavesicSilver Contributor
Hi DeejayJohn,
You can try these steps to make a Pivot table with multiple dates:
Step 1: Create a new pivot table
- Select the data that you want to include in the pivot table.
- Click the Insert tab.
- In the Tables group, click PivotTable.
- In the Create PivotTable dialog box, select the New Worksheet option.
- Click OK to create the pivot table.
Step 2: Add the required fields to the pivot table
- Drag the NAME field to the Row Labels area of the pivot table.
- Drag the STATUS field to the Filters area of the pivot table.
- In the Filters area, click the All checkbox next to the STATUS field.
- Clear the checkbox next to the Inactive status.
- Click OK to apply the filter.
- Drag the ARRIVAL DATE field to the Values area of the pivot table.
- Change the value calculation for the ARRIVAL DATE field to Maximum.
- Drag the MAN-DAYS field to the Values area of the pivot table.
- Change the value calculation for the MAN-DAYS field to Sum.
Step 3: Calculate the total number of man-days consumed to date
To calculate the total number of man-days consumed to date, you can use the following calculated field:
Total Man-Days Consumed to Date = IF([STATUS] = "Active", [MAX of ARRIVAL DATE] + [MAN-DAYS], [MAN-DAYS])
This calculated field will return the total number of man-days consumed to date, even for workers who are still active.
To add this calculated field to the pivot table, follow these steps:
- Click the PivotTable Analyze tab.
- In the Calculations group, click Calculated Field.
- In the Calculated Field dialog box, enter the following information:
- Name: Total Man-Days Consumed to Date
- Formula: IF([STATUS] = "Active", [MAX of ARRIVAL DATE] + [MAN-DAYS], [MAN-DAYS])
- Click OK to add the calculated field to the pivot table.
- Drag the Total Man-Days Consumed to Date field to the Values area of the pivot table.
Step 4: Remove the duplicate rows
To remove the duplicate rows from the pivot table, you can use the following filter:
- In the PivotTable Analyze tab, click the Filter button.
- In the Filters pane, click the Total Man-Days Consumed to Date field.
- In the Filter dialog box, click the Unique Values checkbox.
- Click OK to apply the filter.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)- DeejayJohnCopper Contributor
Thanks. I got an idea on what steps to follow.
I'm just having problem on the formula in calculated field.