How can i calculate the balance in excel's powerpivot? - excel

I'm doing this in powerpivot Excel 2013
So i have a table what looks a little like this:
name debit/credit amount Date
Jane C €10,00 01-01-2013 01:00
Jane C €10,20 01-01-2013 06:20
Jane D €12,30 03-01-2013 14:13
ETC
The table is sorted by date
I want to create an extra column in my data model so the table looks like this:
name debit/credit amount Date Balance
Jane C €10,00 01-01-2013 01:00 €10,00
Jane C €10,20 01-01-2013 06:20 €20,20
Jane D €12,30 03-01-2013 14:13 €7,90
ETC
Any advice how to do this?

You need to use DAX CALCULATE for this.
To simplify it a bit I first added a column:
=if([debit/credit]="C",[amount],-[amount])
Then I did balance with this:
Balance = CALCULATE(sum([adjAmount]),FILTER('Table1',[date]<=EARLIER([date])))
It is possible to do it with a single formula but it is more complicated than my sluggish brain can handle now.
UPDATE
Sorry, I missed out on the condition for handling multiple names.
Balance =CALCULATE(sum([adjAmount]),FILTER('Table1',AND([date]<=EARLIER([date]),[name]=EARLIER([name]))))

Just use two SUMIF functions, one to sum the credit and one to sum the debit, then subtract the debit from the credit. Use one absolute reference and one relative so that when it is copied down the column the absolute reference remains the same. Enter this into E2 and drag down:
=SUMIF($B$2:B2,"C",$C$2:C2)-SUMIF($B$2:B2,"D",$C$2:C2)

Related

INDEX MATCH with Two Criteria - Error w/ Cell Autofill

I am working on a hiring trends report and have an Excel table with multiple entries per ID/individual (as several individuals have left and been rehired over years). The table looks something like this:
WORKSHEET: SHEET1
A B C D
ID Name Location Hire Date
1122 Karen Chicago 01/01/2018
1038 Tom Chicago 05/22/2016
2845 Angel Pittsburgh 11/15/2016
1122 Karen New York 10/08/2013
4992 Mallory Seattle 09/14/2015
2845 Angel Pittsburgh 07/21/2011
1122 Karen Pittsburgh 08/22/2011
I have created a new table with only one entry per person and their most recent hire date. The next step is to populate the table with location data based on the person's ID and specified hire date.
My approach was to use an INDEX-MATCH expression with two match statements (one for ID and one for hire date):
=INDEX('SHEET1'!$C$2:$C$2000,
MATCH('SHEET2'!A2,'SHEET1'!$A$2:$A$2000,0),
MATCH('SHEET2'!D2,'SHEET1'!$D$2:$D$2000,0))
The first row where I enter the expression retrieves the correct location data. However, when I attempt to populate the remaining rows in that column, I get a #REF! error, as illustrated below.
WORKSHEET: SHEET2
A B C D
ID Name Location Hire Date
1122 Karen Chicago 01/01/2018
1038 Tom #REF! 05/22/2016
2845 Angel #REF! 11/15/2016
4992 Mallory #REF! 09/14/2015
I've tested each INDEX-MATCH expression separately (first testing for a match only on ID and then testing for a match only on hire date). Each one works separately, and as shown above, it does work for the first row--it just will not autofill for other rows. I've also checked SHEET1 and each individual definitely has the correct matching criteria on SHEET2 for referencing.
Can anyone help with either suggesting a way to fix my expression or an alternative way to retrieve the location data based on two criteria? Thanks in advance!
The third argument to INDEX is the column number, which is why you get a #REF error. You can use LOOKUP instead:
=LOOKUP(2,1/('SHEET2'!A2='SHEET1'!$A$2:$A$2000)/('SHEET2'!D2='SHEET1'!$D$2:$D$2000),'SHEET1'!$C$2:$C$2000)
you can use this formula :
=INDEX(Sheet1!C1:C2000;MATCH(1;INDEX((Sheet1!A1:A2000=Sheet2!A1)*(Sheet1!D1:D2000=Sheet2!D1);0;1);0))
so you can use more than one criteria in secend index like this:
=INDEX((criteria1)*(criteria2)*(criteria3);)

counting how many times a name appears in a specific month

I am creating a score sheet in which I would like to count how many times a person played in a specific month. The formula will be on a separate tab/sheet. The table of data will look similar to this:
Month Player1 Player2 Player3 Player4
January Bob Joe Ed John
January Joe Scott Bob Dan
January Dan John Ed Scott
February Bob Ed Joe Dan
February Dan John Ed Scott
February John Ed Bob Dan
I would like to count how many times Bob played in the month of January. This is the code I've tried and it counts only the first roll of my sheet. For example, I get the result of only "1" for Bob in the month of January.
=COUNTIF(INDEX(Scoreboard!$B$2:$H$282,MATCH(Scoreboard!$O2,ScoreBoard!$A$2:$A$282,0,),""&Names!R$5&"")
The "Names" tab will have all the players name and count the number of games played for the selected month. Cell "O2" is where I select which Month I want to see.
Any help will be appreciated!
With data in columns A through E, in G1 enter the month of interest. In H1 enter the name of interest. The in another cell enter:
=SUMPRODUCT(--(A1:A100=G1) * (B1:B100=H1))+SUMPRODUCT(--(A1:A100=G1) * (C1:C100=H1))+SUMPRODUCT(--(A1:A100=G1) * (D1:D100=H1))+SUMPRODUCT(--(A1:A100=G1) * (E1:E100=H1))
Alternatively, you could use a pivot table.

Find repeat names in column B based on date criteria in column A

I have two columns of data in Excel. Column A is an interaction date, and column B is a name. I'm looking to devise a way to identify repeat contacts by the same name that occur within 1 day of each other. eg:
Date Name
2016/01/01 John Wayne
2016/01/01 Paul Friesen
2016/01/01 John Wayne
2016/01/01 Alex Roschenko
2016/01/02 Paul Friesen
2016/01/02 Peter Mansbridge
2016/01/02 Jake Snake
2016/01/03 Paul Feig
2016/01/03 John Wayne
Using only this sample data, the result I would be looking for is 2 (John Wayne and Paul Friesen both repeated in =< 1 day.
I'm not sure if Excel or Access are the better tool to use for this, but I'm more experience in Excel, I just haven't been able to come up with a formula...
Use a helper column.
In a blank column put the following in row 2:
=SUM(COUNTIFS(B:B,B2,A:A,A2+{-1,0,1}))>1
This will return a column of TRUE/FALSE
Then referencing the helper column we use the following array formula:
=SUM(IF($C$2:$C$10,1/COUNTIFS($B$2:$B$10,$B$2:$B$10,$C$2:$C$10,TRUE)))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter when exiting edit mode instead of Enter. If done properly then Excel will put {} around the formula.
This formula counts the unique names that have TRUE in the helper column. So no matter how many times the name has TRUE next to it, it will only be counted once.

Excel Sum If based on month of date range?

I have sheet with a list of users and their holidays taken like so:
Katie 1 01/01/2016
Dave 2 12/02/2016
Dave 2 12/12/2015
Katie 1 17/11/20165
Liam 1 05/01/2016
Marie 1 09/08/2015
Marie 5 23/09/2015
I am then using the following SUMIF formula on my other sheet to return the total number of holidays taken for each person
=SUMIF(Data!A$1:A$1000,A13,Data!B$1:B$1000)
This gives me a result like so:
Katie 2
Dave 4
Liam 1
Marie 6
However, now I want to turn my SUMIF into a SUMIFS which only returns the values for the month of January like so:
Katie 1
Liam 1
I know I can get the month of the date by using =TEXT('Cell Ref',"mmmm") but I'm not sure how I would combine this into an SUMIFS statement.
Can someone please show me how I can do this?
Thanks in advance
You would need to use an Array Formula:
=SUM(IF((Data!A$1:A$1000=A13)*(Month(Data!C$1:C$1000) = 1),Data!B$1:B$1000))
Since it is an Array formula it needs to be confirmed with Ctrl-Shift-Enter when leaving edit mode. Then copied down.

Count cells if two criteria - but sumproduct didnt work (Excel

I need help with this, please:
I have a table with lot of data and I need count rows where is specific name and specific time (for example John 7:15, Tom 7:00, Nick 8:00 and I need know how many times in table is John beetven 7:00-08:00 and so on...)
countif(s), sumproducts didnt working for me :(
Thanks
First, select your entire times Column and make sure it is all in hh:mm:ss (hours, minutes, seconds) format.
In Column C, set up a Countifs function, with:
The first criteria range being Column A (names)
The first criteria being the name you are looking for, in quotes
The second criteria range being Column B (times)
The second criteria being ">(insert minimum hh:mm:ss value here)"
The third criteria range being Column B (times)
The third criteria being "<(insert maximum hh:mm:ss value here)"
If you can create extra columns, then you may want to try this. I assume the times may have minutes, so that you may have "nick" in cell C2 and "8:15" in cell D2. You want to know how many Nicks there are between 8 and 9? Then in cell E2, extract the hour from the time with "=HOUR(D2)".
Then use COUNTIFS to handle multiple criteria. Let's say you put "Nick" in cell A1 and the number 8 in cell A2, for 8am. Then in cell A3 you could write "=COUNTIFS(C2:C5,A1,E2:E5,A2)" .
I like countifs (with an s) better than countif because it handles multiple criteria better.
Hope this helps.
Column A:
John
John
John
John
John
Tom
Nick
Nick
Nick
Nick
Nick
Nick
Nick
Tom
Tom
Column B:
7:15
8:15
9:15
7:15
7:15
7:00
8:00
9:00
10:00
11:00
12:00
13:00
14:00
7:00
8:00
Formula in C2 cell:
=COUNTIF(A:A,A2)
Formula in D2 cell:
=COUNTIFS(A:A,A2,B:B,B2)

Resources