Excel Power Query: transform two cells into two duplicate rows - excel

I have an Excel Power Query that imports and transforms a CSV data-transfer file from what is essentially a timesheeting web application ready for importing into our payroll application, again via CSV. Certain rows have both ‘daytime’ and ‘night-time’ hours in two separate fields. I need to transform these two fields into two separate rows adding a custom ‘rate’ field for each. To illustrate:
Name day hours night hours
A.N Other 6 4
Transforms into:
Name day hours night hours hours rate
A.N Other 6 0 6 rate1
A.N Other 0 4 4 rate2
The payroll application can only process ‘hours’ and ‘rate’ on individual rows
I have gone through the full ‘M’ specification and nothing jumps out.
I have googled and there’s lots of stuff about removing duplicates, not a lot about creating them!
To be honest, I don’t really know where to start. Any help would be warmly received.

The key step here is to select the day hours and night hours columns in your query editor and choose Unpivot Columns under the Transform tab.
This will yield:
Name Attribute Value
A.N Other day hours 6
A.N Other night hours 4
Once you do that you can create custom columns using the following rules:
if [Attribute] = "day hours" then [Value] else 0
and analogously for the night hours column:
if [Attribute] = "night hours" then [Value] else 0
From there you can rearrange, rename, and delete columns as desired.
You can also create a custom rate column with similar logic using the Attribute column or one of the hours columns.

Related

Excel Table of Daily hours summarized by week number for a user

I'm having a hard time getting my head around what I think is a simple enough problem.
I have an Excel table of hours by day for each user i.e.:
Date1, Date1+1, Date1+2, Date1+3,... Date1+n
User1 8 8 4 6 ... 2
User2 5 2 8 3 ... 7
User3 0 7 5 0 ... 8
For forecasting purposes this grid looks several months into the future.
I do my work daily, others want it by week. I'd like to automatically generate the same table of data but rolled up by WeekNum.
I tried setting a year-weeknum at the top of the daily table and then using a SumIfs function to compare the user name and week num to sum up the daily hours in another tab for weekly data but I just couldn't get it to function properly.
=SUMIFS('Act - Forecast Hours'!$G$6:$AAL$35,'Act - Forecast Hours'!$A26,$A25,'Act - Forecast Hours'!S$4,O$3)
I think I'm overcomplicating a solution, any help is appreciated.
TIA
Rob
OK, I may have come up with an approach.
Since on my main Hourly Sheet the format is fixed, i.e. each week is 7 days and increments.
I setup a second sheet where I called a vertical and a horizontal offset and used the following formula:
=SUM(OFFSET('Act - Forecast Hours'!$G$9,$A5,D$2,1,7))
$A5 and D$2 refer to offset counts that increment by 7. As you copy the formula to each cell it increments the Row / Column to point to the right spot. Then for the Height and Width I look at a grid 1 row high and 7 wide to select each day of the week.
It works, I'm happy. I'm certainly interested in a more refined approach if there is one :-)
Thank You to anyone that does read through the question!
Regards
Rob

Spread values over a year in Excel

I need to forecast project values along the year.
I have for example:
3 'A' Projects per year
5 'B' Projects per year
20 'C' Projects per year
Projects all worth 10$.
Setup range:
I need to spread their values in a months table, in google sheet (or excel) using formulas.
Expected result :
I thought it was a very similar issue than "one every N-th column", so I tried using modulo:
In E2:
=$C2*ROUND(DIVIDE($B2,12))+IF(MOD(MONTH(E$1),12/$B2)=0,$C2,0)
But it works only when 'nb per year' is a divider of 12 (1,2,3,4,6..)
I don't need any particular spread rule (random, counting from the first month ..) as soon as I have N projects total in the whole year.
How can I do?
Thanks a lot for the help !
Arno
This will do what you want:
=$C2*(INT(COLUMN(B:B)/(12/$B2))-INT(COLUMN(A:A)/(12/$B2)))
My spacing is slightly different than yours, but it is close.

MS Access Query - display data for each month over multiple years as columns

OK, I am very new at this and have been googling things for the past few hours and have not found anything. Maybe I'm not looking for the right thing or I'm not looking hard enough but I am here now.
I have 3 calculations I need to do for each month (over 5 years) to be displayed as columns (3*12*5=180 total columns). I have mock formulas in Excel:
Fraction of Month =IF(AND(FEStart>=s01Y15,FEStart<=e01Y15),IF(FEStart=s01Y15, 1, ((e01Y15-(FEStart))+1)/DAY(e01Y15)),IF(AND(FEEnd>=s01Y15,FEEnd<=e01Y15),IF(FEEnd=e01Y15, 1, ((FEEnd)-(s01Y15))/DAY(e01Y15)),IF(FEEnd<=e01Y15, 0, IF(FEStart<=s01Y15,1,0))))
Year of Person =IF(AND(FEStart>=s01Y15,FEStart<=e01Y15),1,IF(AND(FEEnd>=s01Y15,FEEnd<=e01Y15),INT((s01Y15-FEStart)/365)+1,IF(FEEnd<= e01Y15, 0, IF(FEStart<=s01Y15,INT((s01Y15-FEStart)/365)+1,0))))
Monthly Salary =([Fraction of Month]*(SF/12))*(1.03^([Year of Person]-1))
Where
FEStart is the Start Date of the Person (entered by user)
s01Y15 is the start of the first month in 2015 (parameter set by me)
FEEnd is the End Date of the Person (entered by user)
e01Y15 is the end of the first month in 2015 (parameter set by me)
SF is the Annual Salary of the person (entered by user)
I understand that IF() has to be changed to IIF() and to use AS to name the field in the query for the sql code. However, I’m trying to see if I can make some sort of loop so I don’t have to manual change the variables and have 180 line written out. If I have to do that, I will. But I would really rather not.
Is there some way to use a while loop or for loop or some other loop to have MS Access create these 180 columns for me, without having 180 lines of code? Or do I just have to copy and paste a ton?
DISCLAIMER: I am using MS Access 2013. Also, I have some experience with VBA code in Excel (and I’m far more comfortable using Excel than MS Access) but am unsure of how to add VBA code to a query (I have added it to my forms).
I also had the idea to change the values of s01Y15 and e01Y15 in each loop but that might be a bit more complicated too so I just have (12*2*5=120) 120 variables set to the start and end dates of every month (which is probably not the best idea in retrospect). Anyways I still cannot get a loop to work in a query (if it even is possible).
EDIT: Not sure if this is helpful, but this is what I have:
Input data for People Table:
Person’s name (separated into f/l), Start/End Date (FEStart/FEEnd), Salary (SF).
People Query to show: Person’s name, Start/End Date (FEStart/FEEnd), Salary (SF), & the 180 columns I described above.
Restrictions on Calculations: Fraction of a Month should be a positive number no larger than 1. Year of person starts as a 1 and increases (by one) after each year (essentially infinitely but I am only doing 5 years – so with a max of 5). Monthly salary can be infinite.
Here is an example for an entry in the People table:
FName | LName | FEStart | FEEnd |SF
Anakin | Skywalker | 7/1/2017 |6/30/2019 |120,000.00
This is a little oversimplified because really the start and end dates are pulled form another table, connected by the “people id”.
Please see the link for the calculations.

Excel - Evaluate multiple cells in a row and create report or display showing lowest to highest

In an Excel 2003 spreadsheet, I have the top row of cells calculating the number of days and hours I have worked on something based on data I put in the cells below for each category. For example I enter the time spent on Programming, Spoken languages, house, piano, guitar...etc. The top cell in each category will keep track of and display how many days and hours I spent as I add the time spent for each category each day. I want to evaluate this top row and then list in a "report" (like a pop up box or another tab or something) in order from least amount of time to the most amount of time. This is so I can see at a glance which category is falling behind and what I need to work on. Can this be done in Excel? VBA? Or do I have to write a program from scratch in C# or Java? Thanks!
VH
Unbelievable... I've been scolded for trying to understand an answer and requested to mark this question answered. I don't see anything to do this and could not find anything that tells you how, so I'm just writing it here. MY QUESTION WAS ANSWERED... But thanks anyway...
Consider the following screenshot:
The chart data is built with formulas in columns H3:I3 and below. The formulas are
H3 =INDEX($B$3:$F$3,MATCH(SMALL($B$2:$F$2,ROW(A1)),$B$2:$F$2,0))
I3 =INDEX($B$2:$F$2,MATCH(SMALL($B$2:$F$2,ROW(A1)),$B$2:$F$2,0))
Copy down and build a horizontal bar chart from the data. If you want to change the order of the source data, use LARGE() instead of SMALL().
Alternative Approach
Instead of recording your data in a matrix, consider recording in a flat table with columns for date, category and time spent. That data can then easily be evaluated in many possible ways without using any formulas at all. The screenshot below shows a pivot table and chart where the data is sorted by time spent.
Edit after inspecting file:
Swap rows 2 and 3. Then you can choose one of the approaches outlined above.
Consider entering the study time as time values. It is not immediately clear if your entry 2.23 means 2 hrs and 23 minutes, or 2 hrs plus 0.23 of an hour, which totals to 2hrs, 13 minutes.
If you are using the first method, then all your sums involving decimals are off. For example, the total for column B is 7.73 as you sum it. Is that meant to be 7 hrs and 73 minutes? That would really be 8 hrs and 13 minutes, no? Or is it meant to be 7 hrs and 43 minutes? You can see how this is confusing. Use the colon to separate hrs and minutes and - hey - you can see human readable time values and don't have to convert minute values into decimals.

Pivot Table column headers using less than

Ive currently got a pivot table showing number of weeks various people work. Id like to create a cumulative table with column headers showing count of people working <2 weeks, <4 weeks, <6 weeks and so on.
Currently I can only get the column headers to show independent count so for instance 2 people worked 2 weeks, 1 person worked 4 weeks. Id like to show 2 people worked =<2 weeks, 3 people worked =< 4 weeks. Is this possible with a pivot?
You should be able to get something similar to your requirements with running totals. I created a very simple set of data, two columns with name and number of weeks, to use as source for a pivot table. I then used Weeks as the Column Label, Name as the Row Label and Count of Name as the value. This initially gave me a value of one where a person had worked a certain number of weeks. I then changed the Field Settings for the value to show a Running Total in Weeks.
Hopefully the attached picture will make this clearer.

Resources