Really appreciate your help with this ! I am trying to analyze some data in power bi and this is how the data is current displayed ( just an example )
Table look like this :
I am not allowed to post a pic but i hope this understand ( bold is header and the rest is the content )
1)Company 2)No of error 3)No of time to be used
A 1 3
A 4 1
B 1 2
B 1 2
C 0 1
I want the table to change into this :
1)Company 2)No of error 3)No of time to be used
A 0 1
B 0 1
C 1 1
So to explain this : so it sums what is for the same company and if the eroors are >1 then will display 0 otherwise will be 1 . For how many time is used it's the other way , if it's been used once it will 1 otherwise 0.
The purpose for this will be to calculate for a speacific period : No of errors/ no of time used *100. ( so it will count how many 1s have been in that period and do the maths )
I have used an if measure but it doesn't help as i can't count ifs ( not sure if it makes sense )
Thanks a lottt! :)
Hello Please try this code:
You need to create "New Table" command,then paste the code:
Full DAX Code:
NewTable =
ADDCOLUMNS (
VALUES ( YourTable[Company] ),
"Test1", CALCULATE ( IF ( SUM ( YourTable[No of error] ) > 1, 0, 1 ) ),
"Test2", CALCULATE ( IF ( COUNT ( YourTable[Company] ) >= 1, 1, 0 ) )
)
If we test it,
Add company to a table visual and then add the following two measures.
Measure1 = INT( NOT( CONVERT( SUM('Table'[No of error]), BOOLEAN)) )
Measure2 = INT( CONVERT( SUM('Table'[No of time to be used]), BOOLEAN))
I have 2 tables and need to use criteria from table1 (Team) to look up information from Schedule2 (Team's Schedule for the year) and then use that array from Schedule2 to find the matches in table1 (opponents) and pair that with the criteria of matching the position within table 1 (position = position) to then sum up the associated numbers that match (2021 opp position points) to calculate the expected total points for the year.
In English: use the team to look up the schedule, use the schedule to look up the array of opponents the team has for the year, use the array of opponents for the year to find the opponents in table1, and then match the position of the current row to the position that is playing each of those opponents, and then sum up the associated points.
Goal: This is to calculate a forecast of each team's position's total points for the year based on how many points their opponents for the year are currently giving away to each position.
Explained Example: So if Dallas WR plays NYG, MIA, WAS, and MIA again, sum up the total points NYG, MIA, WAS, and MIA are currently giving to WRs they are currently play against.
FYI WR = Wide Receiver RB = Running Back, TE = Tight End D/ST = Defense string, QB = Quarterback
I can't use helper cells and need a single formula. Schedule2 will give duplicate values (Some teams play the same team twice and each of those values need to be calculated and not considered unique and not counted just once.
The current formula I have is below but it only seemed to work for one row and didnt work when I drug it down to the row below. could be a referencing issue but I didnt notice anything that would cause this.
The first part of the formula is meant to get the total for the non-duplicated values and the second is meant to get the duplicated values.
= SUM( IF( ISERROR( MATCH( Table1[[#All],[Position]],G14,0)
* MATCH(Table1[[#All],[Opponent]],INDEX(Schedule2,0,MATCH(Table1[#Team],Schedules!$AU$3:$CA$3,0)),0) ),
0,
Table1[[#All],[2021 Opp Position]]))
+ SUM( IF( ISERROR( MATCH( Table1[[#All],[Opponent]],
IF( COUNTIF( INDEX( Schedule2, 0, MATCH(Table1[#Team],Schedules!$AU$3:$CA$3,0) ), INDEX(Schedule2,0,MATCH(Table1[#Team],Schedules!$AU$3:$CA$3,0)))=2,
INDEX(Schedule2,0,MATCH(Table1[#Team],Schedules!$AU$3:$CA$3,0)),
""), 0 )
* MATCH(Table1[[#All],[Position]],G14,0)
* MATCH(Table1[[#All],[Opponent]],INDEX( Schedule2,
0,
MATCH(Table1[#Team],Schedules!$AU$3:$CA$3,0) ),0) ),
0,
Table1[[#All],[2021 Opp Position]] ) )
I am trying to calculate the loan repayment schedule for a loan. however the process to get (and repay) a loan could look like this.
some details of loan:
{loanValue=10000, interest=0.1, termMonths=12};
Apply for loan on 6 jan -- but i specify I would like to repay End of Month.
Get funds on the 15th (effectively starting the loan)
I repay my first repayment on the 28th of Jan ( this is the specified EoM date)
I can easily work out the:
Repayment amount:
-PMT((1+0.1)^(1/12)-1,12,10000) $=877.16
Capital portion:
-PPMT((1+$B$2)^(1/12)-1,1,12,10000) = $797.41
Interest portion``:
-IPMT((1+$B$2)^(1/12)-1,1,12,10000) = $79.74
However, I am not sure how to adjust the first months repayment amount ( and effective calculations) to support that initial partial month?
The following is how far i got on a generic function for this:
Private Function createRepaymentSchedule(TotAmnt, anIntRate, nPER, startDate, processDate)
Dim rs As DAO.Recordset
Dim RT As Double
Dim RES As Double
RT = (1 + anIntRate) ^ (1 / 12) - 1
Dim Sql As String
Pval = TotAmnt
For i = 1 To nPER
cap = -PPmt(RT, i, nPER, TotAmnt)
intr = -IPmt(RT, i, nPER, TotAmnt)
Pval = Pval - (cap)
Debug.Print (i & "~" & Round(cap, 2) & "~" & Round(intr, 2) & "~" & Round(Pval, 2))
Next i
A lot of this depends on the loan terms and conditions. The answer below is based on some assumptions (that I would rather verify by comment in advance):
Continuous compounding
Payment on last working day of month after the first payment is treated the same as payment on last day of month
The Process Date is not used in any calculations, so I cannot incorporate it.
The Start Date is the effective loan origination date.
The loan termination date is the last day of the month nPer months after the Start Date
Normally PMT, PPMT, and IPMT are based on another assumption, which is almost never true in reality : payments are uniform. So each period is exactly the same duration, down to the second. The fact that one month is shorter than another and the real payment dates are on working days is usually not a an important factor, so PMT does a "good enough" approximation. However, your first payment date occurring in only half of a period, will make a material difference - especially to the PPMT and IPMT, so your point is correct. These cannot be used.
At first, I attempted a financial trick to answer the question: roll back the loan date to the start of the month and set the loan amount = the PV of the loan as of the real start date (-15 days). That works financially, but it creates a problem in the schedule of Principle, Interest and Capital. Rather than tweak it, I simply did what you proposed: build a new PPMT that is not only based on your start date, but also incorporating your "last weekday of month" requirement. The result is something that would match up to banking standards.
This could be built in VBA as you proposed, but I decided to stick with pure Excel as I am finding that lately the LET is an underutilized approach and solving it with LET would have its own merits. So, this solution is based the Excel LET function and it produces a Dynamic Array that will spill onto the worksheet. It does require Excel 2016 or Microsoft 365. If that is a problem, tell me in comments and I can convert this to VBA (but with some really different methods).
Set Up
I put your key variables (TotAmt, anIntRate, nPer, startDate, and processDate) into cells B1 through B5. NB: processDate is not used. The results are placed in A8, with headers in A7:F7 to label each series of values.
To get started, I created two helper ranges that are also part of the output: Item and Date. I could have incorporated these into the formula, but I think it is better to expose them so that you can see the schedule.
Item is simple a vertical sequence =SEQUENCE( B3 + 1,,0 ). Date is a dynamic array based on a formula that computes the last working day of the month:
=IF( A8#, WORKDAY( EOMONTH( startDate, A8# - 1 ) + 1, -1 ),
startDate )
NB: your last weekday is 28 Jan. You might be in a SUN-THU country.
There is another way to compute last weekday that is based on WEEKDAY
that would allow you to shift it to your country's schedule. If you
need that, ask for it in the comments.
The Formula
I put the following formula into C8:
=LET( loanAmt, B1,
anInt, B2,
nP, B3,
startD, B4,
pmtDates, B8#,
v, SEQUENCE( nP+1,,0 ), h, TRANSPOSE( v ),
pp, SIGN( h ),
ones, SIGN( TRANSPOSE( pp + 1 ) ),
stagr, (v - h + 1) * (v >= h),
dlyInt, ( 1 + anInt ) ^ (1/365 ) - 1,
fvFactors, ( 1 + dlyInt ) ^ ( pmtDates - startD ),
fvarray, INDEX( fvFactors, stagr, ) * SIGN( stagr ),
guess1, PMT( ( 1 + anInt ) ^ (1/12 ) - 1, nP, loanAmt ),
rseq1, MMULT( fvarray * ( loanAmt*(1-pp) + guess1*pp), ones), guess2, guess1 * ( 1 + INDEX( rseq1, 13 )/loanAmt ),
rseq2, MMULT( fvarray * (loanAmt*(1-pp) + guess2*pp), ones ), guess3, guess2 * ( 1 + INDEX( rseq2, 13 )/loanAmt ),
rseq3, MMULT( fvarray * (loanAmt*(1-pp) + guess3*pp), ones ), guess4, ROUND( guess3 * ( 1 + INDEX( rseq3, 13 )/loanAmt ), 2 ),
rseq4, MMULT( fvarray * (loanAmt*(1-pp) + guess4*pp), ones ),
prin, INDEX( rseq4, v+1, ) - INDEX( rseq4, v, ),
i, (TRANSPOSE(loanAmt*(1-pp) + guess4*pp) - prin) * --( v +1 > 1 ),
cflows, TRANSPOSE(loanAmt*(1-pp) + guess4*pp),
tap, IFERROR( INDEX( cflows, v+1, SEQUENCE( 1, 2 ) ), prin ),
tapi, IFERROR( INDEX( tap, v+1, SEQUENCE( 1, 3 ) ), i ),
tapic, IFERROR( INDEX( tapi, v+1, SEQUENCE( 1, 4 ) ), rseq4 ),
tapic )
How it works
I'm a bit pressed at the moment, so I cannot do a detailed explanation right now, so I will give a high level view:
The input variables are straight forward - as mentioned, the Dates are a helper column, so pmDates are the range of payment dates that were created by the last-weekday-of-month range mentioned above.
Array Shapers are just sequences of indexes and matrices that will be used in the shaping and calculation of the financials. They are used next to create a set of financial arrays for future value factors that will be used to create all of the financial outputs.
Payment Convergence is an iterative approach to creating the adjusted real payment amount (i.e. a replacement for PMT) that will truly balance the loan if paid according to the pmtDates that were input. This uses iterations that start with a guess and then adjusts the guess in each iteration. It converges faster then Newton-Raphson and is probably over-engineered for small loan/interest values, but can reliably scale to 7 figure loans and double digit interest rates. The final output is rseq4 which is the remaining Capital schedule that you asked for.
Prin (PPMT), i (IPMT), and cflows (payments) are calculated into columns in Results Columns. Result Table Construction then appends these by using nested over-indexing of the columns to form a single table called tapic (table annuities prin interest capital) which is the final result.
If it is valuable, I can expand on the methods and give more detail about the financials - just ask in comments, but gotta go for now.
I am having trouble figuring out an index function. My datasheet is as follows
Tab 1 - complete list of all subcompanies held by all holding companies
- The first column shows holding companies
- the second column shows the subcompanies held by each holding company
- the third, fourth and fifth column give the key financials of these subcompanies (EBITDA)
The tabs after Tab 1 are tabs for every holding company. In these tabs I have a section where I want to only include the subcompanies from Tab 1 with an EBITDA higher than 20 million
Example:
Holding company A has the following subcompanies: Sub1 (EBITDA:10m), Sub2 (EBITDA: 21m), Sub3 (EBITDA: 15m).
In the tab of company A I want to only display the information of Sub2 as it meets the minimum threshold
The function I have now displays all information of each subcompany per holding company regardless of their EBITDA:
=IFERROR(INDEX(Tab1!D$5:D$337,SMALL(IF(Tab1!$C$5:$C$337=$C$6,ROW(Tab1!D$5:D$337)-MIN(ROW(Tab1!D$5:D$337))+1),ROWS(B$55:B55))),"")
Tab1 Column D has all the subcompany names
Tab1 Column C has all holding company names
Column B is where I insert the subcompanies in the holding company tab
The output provides all subcompanies per holding, but I only want the subcompanies per holding with an EBITDA equal or larger than 20m
How can I add a criteria to filter if one or more of the 3 years worth of EBITDAs (Tab1 Column N, O & P) per subcompany is equal or larger than 20m?
Many thanks in advance!
Change the criteria in the IF statement from:
Tab1!$C$5:$C$337=$C$6
to also check columns N, O or P being over 20m:
(Tab1!$C$5:$C$337=$C$6)*((Tab1!$N$5:$N$337>20000000)+(Tab1!$O$5:$O$337>20000000)+(Tab1!$P$5:$P$337>20000000))
You are using a FormulaArray, however, you could also use this standard formula (entered at B6):
= IFERROR( INDEX( 'Tab1'!$D$5:$D$337,
AGGREGATE( 15, 6, ROW(B:B) /
( ( 'Tab1'!$C$5:$C$337 = $C$6 ) *
( ( 'Tab1'!$N$5:$N$337 > 20 ) + ( 'Tab1'!$O$5:$O$337 > 20 ) + ( 'Tab1'!$P$5:$P$337 > 20 ) <> 0 ) ),
ROWS( B$5:B5 ) ) ), "" )
I can't find the solution to this. Excel table with 3 Columns:
[#ID] -> counter of rows
[value] -> just a nunch of positives a negatives numbers
[negative] -> 1 when value column is negative 0 when positive and cumulating negative streak
Formulas
[#ID] = ROW()-ROW(['# ID])+1
[negative] = IF([#['# ID]]=1,IF([#value]<0,1,0),IF([#value]<0,1+OFFSET([#negative],-1,0)),0))
How can keep this working when filtering some rows?
Without filter
With filter
Assuming the Table starts at row 3 or higher try this formula:
= IF( [#value] >= 0, 0,
IF( [#['# ID]] = 1, 1,
SUM( 1, OFFSET( [#negative],
IF( SUBTOTAL( 9, C2:C$3 ) = SUBTOTAL( 9, C$3:C3 ), -2, -1 ), 0 ) ) ) )
Suggest to see the following pages for additional information about the functions used:
Excel functions (alphabetical)
SUBTOTAL function
OFFSET function