See attached and below for table data structure example: Data Structure.xlsx (10.7 KB)
I have a dataset like this:
Name | Date | Cost | Charge | Hours |
---|---|---|---|---|
Sally | 1/01/2030 | 500 | 0 | 10 |
Sally | 2/01/2030 | 500 | 0 | 10 |
Sally | 3/01/2030 | 0 | 1000 | 10 |
Sally | 4/01/2030 | 0 | 1000 | 10 |
Muhammed | 1/01/2030 | 250 | 0 | 5 |
Muhammed | 2/01/2030 | 250 | 0 | 5 |
Muhammed | 3/01/2030 | 0 | 500 | 5 |
Muhammed | 4/01/2030 | 0 | 500 | 5 |
Muhammed | 5/01/2030 | 0 | 500 | 5 |
Gavic | 1/01/2030 | 400 | 0 | 8 |
Gavic | 2/01/2030 | 400 | 0 | 8 |
Gavic | 3/01/2030 | 0 | 800 | 8 |
Gavic | 4/01/2030 | 0 | 800 | 8 |
Gavic | 5/01/2030 | 0 | 800 | 8 |
Gavic | 6/01/2030 | 0 | 800 | 8 |
I assumed the below structure is better but now I’m not sure. Notice how Cost and Charge are pivoted into their own column and $ includes both costs:
Name | Date | Type | $ | Hours |
---|---|---|---|---|
Sally | 1/01/2030 | Cost | 500 | 10 |
Sally | 2/01/2030 | Cost | 500 | 10 |
Sally | 3/01/2030 | Charge | 1000 | 10 |
Sally | 4/01/2030 | Charge | 1000 | 10 |
Muhammed | 1/01/2030 | Cost | 250 | 5 |
Muhammed | 2/01/2030 | Cost | 250 | 5 |
Muhammed | 3/01/2030 | Charge | 500 | 5 |
Muhammed | 4/01/2030 | Charge | 500 | 5 |
Muhammed | 5/01/2030 | Charge | 500 | 5 |
Gavic | 1/01/2030 | Cost | 400 | 8 |
Gavic | 2/01/2030 | Cost | 400 | 8 |
Gavic | 3/01/2030 | Charge | 800 | 8 |
Gavic | 4/01/2030 | Charge | 800 | 8 |
Gavic | 5/01/2030 | Charge | 800 | 8 |
Gavic | 6/01/2030 | Charge | 800 | 8 |
Two questions I have:
- Which Data Structure do you recommend and why?
- Whats the simplest way to do this transform? Is there a way to use unpivot instead of replace? I feel like replace is bad practice for some reason.