Can someone explain to me why I am receiving this error?
The 'if' statement seems to look fine to me, but I am just a little unfamiliar with Google Spreadsheets and if there are syntax differences:
=IF((D8) >= 2600 , "$1.39", IF((D8) < 2600 AND >= 2500, "$1.40", IF((D8) < 2500 AND >= 2400, "1.42", IF((D8) <2400 AND >= 2300, "$1.45", IF((D8) < 2300 AND >= 2200, "$1.50", IF((D8) < 2200 AND >= 2100, "$1.54", iF((D8) < 2100 AND >= 2000, "$1.60", iF((D8) < 2000 AND >= 1900, "$1.65", IF((D8) < 1900 AND >= 1800, "$1.72", IF((D8) < 1800 AND >= 1700, "$1.79", iF((D8) < 1700 , "NEED MORE MILES")))))))))))
As hinted by pnuts in comments, use a lookup table:
1) setup the table (for example) in Cell A1-B14:
Miles Amount
0 Need More Miles
1700 1.79
1800 1.72
1900 1.65
2000 1.6
2100 1.54
2200 1.5
2300 1.45
2400 1.42
2500 1.4
2600 1.39
99999999
2) Assuming input is in cell H2.
put this formula in cell H3:
=VLOOKUP(H2,$A$2:$B$13,2,TRUE)
This takes the value in H2, and looks up a near match in the table, giving the amount as a result.
Hopefully you can adjust this to your specific needs.
Related
I have done some tests myself but all has been unsuccessful, but if I am missing something please feel free to ask for more information.
I have a spreadsheet with contract numbers on the rows and amortizations on the columns, like the following example:
Original Value
2011
2012
2013
2014
2105
1001
2000
10
10
10
10
10
1002
1500
20
20
20
20
20
1003
1200
0
0
15
15
15
1004
3000
0
0
0
0
10
Using DAX is there a good way to make a calculated value for the present value for each of the time frames? As the example below show:
Original Value
PV2101
PV2102
PV2103
PV2114
PV2105
1001
2000
1990
1980
1970
1960
1950
1002
1500
1480
1460
1440
1420
1400
1003
1200
0
0
1185
1170
1155
1004
3000
0
0
0
0
2990
So a calculated value that sums upp all prior amortizations dependant on the date in the x-axis and reduces that amount from the original value.
I can see two options:
You create a pivoted table:
|ID |Year|Value|
|----|----|----|
|1001|2011| 10|
|1001|2012| 10|
|1001|2013| 10|
|1001|2014| 10|
|1001|2015| 10|
|1002|2011| 20|
And then your measure will be trivial:
Calculated Value =
VAR dt_year = YEAR(SELECTED(date[date]))
RETURN SUM(table[Original Value]) +
CALCULATE(SUM(amort[Value]), amort[Year] <= dt_year)
Or you create some measure that adds up the individual columns:
Calculated Value =
VAR dt_year = YEAR(SELECTED(date[date]))
RETURN SUM(table[Original Value]) +
IF(dt_year >= 2011, SUM(table[2011]), 0) +
IF(dt_year >= 2012, SUM(table[2012]), 0) +
IF(dt_year >= 2013, SUM(table[2013]), 0) +
IF(dt_year >= 2014, SUM(table[2014]), 0) +
IF(dt_year >= 2015, SUM(table[2015]), 0)
Option 1 is a lot nicer.
Let's imagine the following table ...
obs
State
Imp
i
i2
1
me
100
100
2
me
90
100
100
3
me
80
100
100
4
me
70
100
100
5
me
1000
1000
100
6
me
900
1000
1000
7
me
800
1000
1000
8
me
0
1000
1000
9
me
2000
2000
1000
10
me
1900
2000
2000
11
gu
20
2000
2000
12
ca
40
2000
2000
13
ca
50
2000
2000
14
ca
30
2000
2000
15
ca
10
2000
2000
as you can see column "i2" is lag (i). What I want to do is:
1.- column "i" finds the maximum value as it progresses, so i want to reset that column
"i" every first "state", in order to get that maximum value of each state.
2.- modify the column "i2" so that it is as follows:
that each first value of "State" (obs 1-me, 11-gu and 12-ca) column "i" has the value
of column "imp"
obs
State
Imp
i
i2
1
me
100
100
100
2
me
90
100
100
3
me
80
100
100
4
me
70
100
100
5
me
1000
1000
100
6
me
900
1000
1000
7
me
800
1000
1000
8
me
0
1000
1000
9
me
2000
2000
1000
10
me
1900
2000
2000
11
gu
20
20
20
12
ca
40
40
40
13
ca
50
50
40
14
ca
30
50
50
15
ca
10
50
50
i have tried with this code, but it doesn't work
data metodo;
set sa80;
retain i;
if first.state then i=max(imp);
else i = max(imp,i);
i2 = lag(i);
run;
data final;
set metodo;
retain i2_aux;
if first.state then i2_aux = total;
else i2_aux = i2;
run;
Hope you could help, and thank you in advance
The main thing it not use an existing variable as the new RETAINed variable because then each time the SET statement executes the value retained is replaced with the value read from the input.
It also helps if the data is sorted by the key variable, although you can use the NOTSORTED keyword on the BY statement to process grouped, but not sorted, data.
data have;
input state $ imp ;
cards;
ca 40
ca 50
ca 30
ca 10
gu 20
me 100
me 90
me 80
me 70
me 1000
me 900
me 800
me 0
me 2000
me 1900
;
data want;
set have ;
by state notsorted;
retain i;
i=max(i,imp);
if first.state then i=imp;
i2=lag(i);
if first.state then i2=imp;
run;
Results:
Obs state imp i i2
1 ca 40 40 40
2 ca 50 50 40
3 ca 30 50 50
4 ca 10 50 50
5 gu 20 20 20
6 me 100 100 100
7 me 90 100 100
8 me 80 100 100
9 me 70 100 100
10 me 1000 1000 100
11 me 900 1000 1000
12 me 800 1000 1000
13 me 0 1000 1000
14 me 2000 2000 1000
15 me 1900 2000 2000
Fixed order of resetting I and LAG(I) call.
I am trying to specify each dimension range (length, width and height) of values specify criteria based on the length, width and height.
In data table I have 3 columns are length, width,height based on the 3 columns I would like to generate status columns which is based on the below mentioned condition range.
Conditions Range
Length, width and height is start from 1 to 300 then A1.
Length, width and height is start from 301 to 650 then A2.
Length, width and height is start from 651 to 900 then A3.
Length, width and height is start from 901 to 1200 then A4
Length, width and height is start from 1201 above then XXX
Data
LENGTH
WIDTH
HEIGHT
DESIRED RESULT RANGE
NA
NA
NA
NA
20000
5000
230
XX
400
300
140
A1
BLANKS
600
400
285
A2
600
400
285
A2
400
300
150
A1
280
230
170
A1
320
320
320
A1
320
320
320
A1
600
400
140
A1
400
300
140
A1
400
300
140
A1
370
320
340
A1
320
240
250
A1
300
200
90
A1
400
290
140
A1
600
400
285
A1
Table and result look like
Any suggestions please
Well, you may try the following dax measure, as it will assign all row to each category, and assign to Other if does not match any of the criteria, do take note due to your data contain NA, therefore all the value is in Text for that need to convert to number during calculation:
Result = IF(Sheet1[LENGTH] = "NA" || Sheet1[WIDTH] = "NA" || Sheet1[HEIGHT] ="NA", "NA",
IF(VALUE(Sheet1[LENGTH])>0 && VALUE(Sheet1[LENGTH]) <=300 && VALUE(Sheet1[WIDTH]) >0 && VALUE(Sheet1[WIDTH]) <=300 && VALUE(Sheet1[HEIGHT]) >0 && VALUE(Sheet1 [HEIGHT]) <=300, "A1",
IF(VALUE(Sheet1[LENGTH])>300 && VALUE(Sheet1[LENGTH]) <=650 && VALUE(Sheet1[WIDTH]) >300 && VALUE(Sheet1[WIDTH]) <=650 && VALUE(Sheet1[HEIGHT]) >300 && VALUE (Sheet1[HEIGHT]) <=650, "A2",
IF(VALUE(Sheet1[LENGTH])>650 && VALUE(Sheet1[LENGTH]) <=900 && VALUE(Sheet1[WIDTH]) >650 && VALUE(Sheet1[WIDTH]) <=900 && VALUE(Sheet1[HEIGHT]) >650 && VALUE (Sheet1[HEIGHT]) <=900, "A3",
IF(VALUE(Sheet1[LENGTH])>900 && VALUE(Sheet1[LENGTH]) <=1200 && VALUE(Sheet1[WIDTH]) >900 && VALUE(Sheet1[WIDTH]) <=1200 && VALUE(Sheet1[HEIGHT]) >900 && VALUE(Sheet1[HEIGHT]) <=1200, "A4",
IF(VALUE(Sheet1[LENGTH])>1200 && VALUE(Sheet1[WIDTH]) >1200 && VALUE(Sheet1[HEIGHT]) >1200 , "XXX",
"Others"))))))
Result:
I have a two tables are data and report.
In data table the following columns are Size A, Size B and Size C, Type and Rank.
In data table I created rank for each type based on the sizes. The purpose of the rank column were multiple matches for same size in this case the rank column will help to decide exact type were match more than one.
In report table the following columns are Size A, Size B and Size C.
In both table the Size A, Size B and Size C columns are common/relationship.
I am trying find out the appropriate type according to the Size A, Size B and Size C from data table into report table.
Data:
TYPE
SIZEA
SIZEB
SIZEC
RANK
A6
420
600
440
11.00
A4
640
600
480
9.00
A5
890
1100
1330
2.00
A6
1335
1100
2350
1.00
A7
890
1100
390
5.00
A8
890
1100
530
3.00
A9
670
1100
540
4.00
A10
670
1100
440
6.00
A11
320
1100
440
10.00
A12
600
400
400
12.00
A13
800
600
400
8.00
A14
1000
600
500
7.00
Report:
SIZEA
SIZEB
SIZEC
DESIRED RESULT-TYPE
400
300
140
A12
A12
250
250
160
A12
600
400
285
A12
400
300
150
A12
280
230
170
A12
320
320
320
A12
320
320
320
A12
600
400
140
A12
400
300
140
A12
400
300
140
A12
370
320
340
A12
320
240
250
A12
300
200
90
A12
400
290
140
A12
I am applying following formula in report table in order to get the appropriate type according to the Size A, Size B and Size C
=INDEX(DATA!$D$2:$D$16,AGGREGATE(15,6,(ROW(DATA!$H$2:$H$16)-1)/(DATA!$H$2:$H$16=1/(1/MAX(((DATA!$E$2:$E$16>=$B3)*(DATA!$F$2:$F$16>=$A3)+(DATA!$E$2:$E$16>=$A3)*(DATA!$F$2:$F$16>=$B3)>0)*(DATA!$G$2:$G$16>=$C3)*DATA!$H$2:$H$16))),1))
How can I apply the same logic in Power BI? Any advise please.
I am looking for new calculate column options. Herewith share the Excel file for your reference
https://www.dropbox.com/scl/fi/iq0gteeyazrg79q7a4tb1/AUTO-MODIFY-REQ.xlsx?dl=0&rlkey=nyyerjsg7if2dz30z9iqo6kdc
Here is another formula that will return the same result as per your current formula, although it is still a long formula, but more easily to understand:
=INDEX($D$2:$D$13,MATCH(MAX(IF($G$2:$G$13<$L3,0,
IF((IF($E$2:$E$13<$K3,0,1)*IF($F$2:$F$13<$J3,0,1))+(IF($E$2:$E$13<$J3,0,1)*IF($F$2:$F$13<$K3,0,1))>0,1,0))
*$H$2:$H$13),$H$2:$H$13,0),1)
So I will break it down to explain how do it working:
Part 1: This if formula is checking comparison of Size C, if your data is lower than than table, the value for the Type will be zero therefore will not be considered at all because zero times any amount will be zero
(IF($G$2:$G$13<$L3,0
Part 2: This part is will first checking comparison of Size A vs Size B, if lower than table than return 0 and apply for other comparison, at then end using If at the beginning to reset the value so than the final value will be 0 or 1
IF((IF($E$2:$E$13<$K3,0,1)*IF($F$2:$F$13<$J3,0,1))+(IF($E$2:$E$13<$J3,0,1)*IF($F$2:$F$13<$K3,0,1))>0,1,0)
Part 3: From the value you calculate, if 0 times any ranking will be zero, so from none zero ranking such as 12 or 9, it will get the max value from the list, most of them are 12
Max((.....)*$H$2:$H$13)
Part 4: Index Match - Finally it is same as your formula first part, but you are using Index row which make it difficult to understand
INDEX($D$2:$D$13,MATCH(Max(...))
A shorter version of your formula by removing unnecessary portion:
=INDEX($D$2:$D$13,MATCH(MAX(IF($G$2:$G$13<$L4,0,
IF(($E$2:$E$13>=$K4)*($F$2:$F$13>=$J4)+($E$2:$E$13>=$J4)*($F$2:$F$13>=$K4)>0,1,0))*$H$2:$H$13),
$H$2:$H$13,0),1)
You can add a colum to your report table like:
Desired = LOOKUPVALUE(DataR[TYPE],DataR[RANK], MAXX(FILTER(DataR, DataR[SIZEA] >= ReportR[SIZEA] && DataR[SIZEB] >= ReportR[SIZEB] && DataR[SIZEC] >= ReportR[SIZEC]), DataR[RANK]))
It first filters the table to find the row where the sizes are more or equal to the report row, selects the rank and then does a lookup to the type.
Result:
I used to have one query that does a bunch of things, one of them is tell me about the salary increase for each employee. Is it due? is it overdue? is it too early for one?
The query kept asking me to enter parameters and after asking this question removing "enter parameter value" in query MS access I broke the one query into a bunch, each query builds on the other until the last one that has the if condition.
Everything worked exactly the way I want it to, except for the if condition (that used to work fine before!!!)
This is my if condition
Eligibility: IIf([MonthsSinceLastIncrease] < 24, IIf([MonthsSinceLastIncrease] >= 18
AND [LastOfRatings] <= 2, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 15
AND [LastOfRatings] = 1, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 9
AND [MonthsSinceLastIncrease] < 15
AND [LastOfRatings] = 1, "Eligible", IIf([MonthsSinceLastIncrease] >= 12
AND [MonthsSinceLastIncrease] < 18
AND [LastOfRatings] = 2, "Eligible", "ok")))), "OVERDUE")
The rule for salary increases are as follows:
If the employee's rating is 3, he gets an increase after 24 months of
his last one
If the employee's rating is 2, he gets one in 12-18
months
If the employee's rating is 1, he gets one in 9-15 months
What happens now, is that for some of the employees, I get only one record and it's correct, but for some employees, I get two records, one of them is correct an the other is not. Now instead of 48 records (what I used to get when the condition worked fine), I get 58.
This is the code for the whole query
SELECT IIf([MonthsSinceLastIncrease] < 24, IIf([MonthsSinceLastIncrease] >= 18
AND [LastOfRatings] <= 2, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 15
AND [LastOfRatings] = 1, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 9
AND [MonthsSinceLastIncrease] < 15
AND [LastOfRatings] = 1, "Eligible", IIf([MonthsSinceLastIncrease] >= 12
AND [MonthsSinceLastIncrease] < 18
AND [LastOfRatings] = 2, "Eligible", "ok")))), "OVERDUE") AS Eligibility
,MonthsSinceLastUpdateQ.LocalID
,MonthsSinceLastUpdateQ.LastOfRatings
,MonthsSinceLastUpdateQ.MaxOfDateOfUpdate
,MonthsSinceLastUpdateQ.MonthsSinceLastIncrease
FROM MonthsSinceLastUpdateQ
,DateOfUpdateQ
GROUP BY IIf([MonthsSinceLastIncrease] < 24, IIf([MonthsSinceLastIncrease] >= 18
AND [LastOfRatings] <= 2, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 15
AND [LastOfRatings] = 1, "OVERDUE", IIf([MonthsSinceLastIncrease] >= 9
AND [MonthsSinceLastIncrease] < 15
AND [LastOfRatings] = 1, "Eligible", IIf([MonthsSinceLastIncrease] >= 12
AND [MonthsSinceLastIncrease] < 18
AND [LastOfRatings] = 2, "Eligible", "ok")))), "OVERDUE")
,MonthsSinceLastUpdateQ.LocalID
,MonthsSinceLastUpdateQ.LastOfRatings
,MonthsSinceLastUpdateQ.MaxOfDateOfUpdate
,MonthsSinceLastUpdateQ.MonthsSinceLastIncrease;
Your help is much appreciated, please note that I barely know coding and have only been learning MS Access as I go, thank you!
Tables in your query not linked. Link related colums in query designer by drag-and-drop, like relationship creation