IF Formula HELP. Nesting - if-statement

I need help with a formula..The situation is..
Daily rate for painting is:
$100 per day for 3 or less days of painting
$90 for each day beyond the first 3.
For example, if you paint for 5.5 days, you get paid $100 for each of the first three days and $90 for each of the remaining 2.5 days giving a total of $525.
How can I put this as a IF formula?

I don't think that needs an IF at all. You could do this:
=MAX(0,(A1-3))*90+(MIN(3,A1)*100)
Subtract 3 from the value in A1. Any result greater than zero you will be multiplied by 90. Any result less than zero will be ignored. Then work out what is smaller: A1 or 3. Whichever is the smallest will be multiplied by 100.

assuming the days is in column A
IF(A1>3, 300+(A1-3)*90, A1*100)

Related

DAX AVERAGE() function differs from table average of column

I am new to DAX and running into a problem with regard to averages.
In PowerBI I am using a table with some dimensions and measures, the measures obviously require some form of summary so the dimension can roll up/summarize the data.
The problem is, I have a measure let's call Minutes that I want to average across the 5 lines of data, I drag the column minutes on set the summary in the table to average and it works perfectly by splitting the data according to the dimensions - data example:
1. A 10
2. A 8
3. A 10
4. A 7
5. A 5
6. B 10
7. B 10
8. B 9
9. B 9
10. B 10
Output in Table:
1. A 8
2. B 9.6
If I want to use that Average of 8 and 9.6 in another calculation and I create a new column called AvgMins = AVERAGE(Minutes) and drag it onto the grid I get a value of 8.8 for both A and B - I understand that the most likely reason for this is due to the calculation happening before the dimension splits and therefore the grid can't handle it - but how do I handle this in the DAX column calc itself?
As pointed out by Jos I was creating the calculation as a column instead of a measure, changing to a measure the normal AVERAGE() works perfectly
You should be using a Measure, not a Calculated Column.
A measure can result in a lot of different numbers - depending on the filter context.
AbgMins = AVERAGE('Table'[Minutes])
w/o any filter will return the average of the Minutes column, which is 8.8. But if you filter it by your category - A and B - it will return the average for all A's and all B's, which is 8 and 9.6.
If you are looking for Average of Average.
AVERAGEX(
VALUES('Table'[CategoryColumnName])
,CALCULATE(AVEARGE('Table'[Minutes]))
)
This if you are looking for Average per category
CALCULATE(
AVERAGE(
AVEARGE('Table'[Minutes]))
,ALLEXCEPT('Table','Table'[CategoryColumnName])
)
)

Creating new calculation to sum a Dax Calculated Measure in Power BI

I have a promised hours calculation that looks at two dates (Coalesce) and gets the number of weeks in the month and then multiply it by the max promised hours for an employee which has a row for every week of the month. The employee could have 5 rows for every entry a week and the promised hours shows up the same as for example 40 for that week, thus why I have to take the max instead of do a sum. But at the end I need to show the total number of promised hours per week for whatever timeframe is chosen in the date slicer per employee.
Promised Hours Calc = CALCULATE(WEEKNUM(Max([CoalesceActualStart_AbsenceStart]),1)-WEEKNUM(MIN([CoalesceActualStart_AbsenceStart]),1))*MAX(FSLData[PromisedHours])
I then need it to do a sum for every employee on the above calculation.
I am getting all sorts of errors trying to do a sum on the calculation as a whole.
What you write is confusing and incomprehensible. That's why you get the errors. As soon as you are able to formulate your problem in such a way that others can understand it, you will understand it yourself and the errors will go away.

(SOLVED using VLOOKUP) Tiered/Nested IF clauses within one cell

Imagine a tiered revenue sharing scheme like this:
Revenue up to 10000 get 100% of it.
Revenue up to 12000 get the above plus 80% of the amount above 10000.
Revenue up to 14000 get the above plus 60% of the amount above 12000.
Revenue up to 16000 get the above plus 40% of the amount above 14000.
Revenue over 16000 get the above plus 20% of the amount above 16000.
E.g. A revenue of 13000 will get you a share of 10000+0.82000+0.61000 = 12200.
I tried making a table (each threshold a column) and calculate the individual fractions using IF clauses and then add them all up. It is very cumbersome. I would like to use only two cells with the entire calculation done in one cell, hard-coded.
If at all possible, extra bonus points if I can have the threshold values (10000, 12000, etc) and fractions (100%, 80%, etc.) in separate cells as parameters for the calculation, maybe something like an array-function?
Thank you very much in advance!
Start your lookup table with a value of 0 and a rate of 100%. In this case, VLOOKUP() with the last parameter equal to 1 will correctly find the required row.
In order not to recalculate all the above rows for each of the values, calculate them in advance and place them in the table as an additional column.
For the first line it will be 0, and calculate all subsequent values using a formula like =C2+(A3-A2)*B2
For such a table, a not very complicated formula will return the correct result:
=(<revenue>-VLOOKUP(<revenue>;<lookup_table>;1;1))*VLOOKUP(<revenue>;<lookup_table>;2;1)+VLOOKUP(<revenue>;<lookup_table>;3;1)
The third parameter in the VLOOKUP() functions increases from left to right: 1 - the base amount, 2 - the interest rate, 3 - the calculated markup for reaching the previous levels.
For the data shown in the figure, the formula is used
=(E2-VLOOKUP(E2;$A$2:$C$7;1;1))*VLOOKUP(E2;$A$2:$C$7;2;1)+VLOOKUP(E2;$A$2:$C7;3;1)

Why does powerbi average/day calculation become inaccurate over longer timespan?

I am trying to create a power BI calculation as an average per day of how many times a code was tripped. The dax calculcation that I have
Count Trips average per Day =
AVERAGEX(
KEEPFILTERS(VALUES('ruledata (2)'[Date].[Day])),
CALCULATE([Count Trips])
)
works fine when the average is being calculated over a couple days. I double checked this by hand and can confirm that it is accurate until at least 2 weeks. However once the time range increases to include months the average starts getting ridiculous and begins displaying average trips /day values that are much higher than the highest number of trips on a single day. I have confirmed that the data in the graph is correct
So I know that the values should reflect what is in the graph. In this two month example the DAX formula calculated the average to be 149.03 but the actual average/day should have been 82.8.
In general is there some sort of error in the DAX formula that I am using that could cause this?
I guess that 'ruledata (2)'[Date].[Day] is the day of the month. So if you take the average it will be wrong because when you take the average of e.g. March and April you will divide the total trips by 31, and not by 61 (30+31). So use 'ruledata (2)'[Date].[Date] instead.

DAX formula for Time

Time formula in Power BI
What I am trying to do:
If any train departed >= 59 sec, then "1", or else "0".
The formula I am using:
=if([Actual-Planned]>=time(00,00,59),"0","1")
This is partially working. It does give me "0" in the case where actual-planned time is 59 seconds, whereas per formula it should give me "1".
It works when I put it as (00,04,59) but does not work for seconds.
Has anyone come across this issue before?
right so this is my formula:
=if([Actual-Planned]<=time(00,00,59),"RTSF","RTSA"), which means if any time a train is less than or equal to 59 seconds it will achived Right time start or else fail, i guess i am getting the output now, as i changed to smaller than or equal to instead of greater. Thanks for your help