DLookup is returning Blank - excel

I'm fairly new to Access, but have most of the basics down because I've used Excel for years. I'm trying to do a DLookup on a table. It's a really large table.
My DLookup is returning blank. It's not giving me an error message or returning "null." It's just blank. I'm searching a text field to return a numerical value. I'm using this below:
Results: DLookUp("[Meas]","[Database]","[Description]='" & [Description] & "'")
The table looks similiar to below:
Description Weight(g) Measure Protein(g)Per Measure Cholesterol(mg)Per Measure
Butter, salted 5 1.0 pat (1" sq, 1/3" high) 0.04 11
Butter, whipped, with salt 3.8 1.0 pat (1" sq, 1/3" high) 0.03 8
Butter oil, anhydrous 12.8 1.0 tbsp 0.04 33
Cheese, blue 28.35 1.0 oz 6.07 21
Cheese, brick 132 1.0 cup, diced 30.68 124
Cheese, brie 28.35 1.0 oz 5.88 28
Any idea what could be causing this? Or do I need to try to put this in VBA?

From the example code you provided, the only issue I'm seeing is that there's a column called Measure in the table, but you are selecting Meas in your DLookup.
Another thing you could try is: creating a new query in Access, switch to SQL View, paste the following SQL and try to execute the query:
select [Meas] from [Database] where [Description]='whatever'"
(this is the SQL equivalent to your DLookup statement)
Does it run without errors?
If yes, does it return any rows?
If neither of this does help, you need to provide more information.
For a start, I'd like to see the exact column names and the exact DLookup statement.
I'm not sure whether you gave us the real data, because you said "The table looks similiar to below". Similar is not enough here!

Related

EXCEL PERCENTILE result is wrong compared to a textbook?

I am helping my son with his math homework, specifically statistics and this is the dataset:
1 2 3 4 5 6 7 8 9 10
I have 10 numbers from 1 to 10.
15 percentile:
in Excel I use the PERCENTILE or PERCENTILE.INC function with .15 and the result is 2.35, why?
The book way. .15*10 = 1.5 th number. There is not 1.5 number so round up to 2 or 2.
20 percentile:
In excel I get 2.8.
Book version: .2*10 = 2 (exact) so take average of 2nd and 3rd value for 2.5
50 percentile or median:
In excel I get 5.5.
Book version .5*10 = 5 (exact) so take average of 5th and 6th value for 5.5 (only match)
75 percentile 7.75:
Book, .75*10 * 7.5 so round up to 8.
Excel
80 percentile:
Excel I get 8.2
Book, .8108, average of 8 and 9 is 8.5.
Obviously Excel is doing more advanced math and additional smoothing, however I have not been able to find the exact math it uses replicate it, hence I will say it is wrong. Other programs and statistical packages match Excel so it is correct, but not useful as I need it.
How can I get Excel to give me the Book version of answers or at least replicate the Excel answers with paper and a basic calculator.
Most importantly I need to find a way to explain to my son that it is OK that the results don't match that he should do it the book way, at least for now or in school.
EDIT: After posting, SO found and similar question: Different results for percentiles in SAS and Excel It seems SAS gives the same results as the book version. The answer there is that Excel and most packages use different interpolation methods. However I need a better explanation for my son and maybe a way to create a proper percentile function for my son, but hopefully without VBA.

excel: sort a list of decimal values based on the order in another column

ID-A
Val-A
22
17.1
4
16.0
7
16.5
ID-B
Val-B
9
15.5
2
19.5
45
17.5
These tables (4 columns in Excel) are my input (here reduced to a minimal working example).
The order of the values in column Val-A (here: largest, smallest, middle) is the order, in which Val-B should be sorted.
That said, the second table should look like:
ID-B
Val-B
2
19.5
9
15.5
45
17.5
The order of the values in the input columns Val-A and Val-B as well as the IDs in ID-A and ID-B are arbitrary.
It is also important to note that the values in Val-A and Val-B are never equal, i.e. none of the values in Val-A will be a value in Val-B.
How can I achieve this in Excel?
I'm suggesting you rank the values in the first table, then match the ranks in the second table to those ranks to get the sort order that you need.
Using ranges:
=SORTBY(D2:E4,XLOOKUP(RANK(E2:E4,E2:E4),RANK(B2:B4,B2:B4),SEQUENCE(3)))
or using structured references:
=SORTBY(Table2,XLOOKUP(RANK(Table2[Val-B],Table2[Val-B]),RANK(Table1[Val-A],Table1[Val-A]),SEQUENCE(ROWS(Table2))))
EDIT
Case where second table has more rows than first.
A bit pushed for time on this so this isn't fully checked. I couldn't get Rank to work with filter, although the documentation suggestions that it should work, but it's OK with index. To avoid a lot of repetition, I've put it in a Let statement like this:
=LET(FilValB,INDEX(TableB[Val-B],1):INDEX(TableB[Val-B],ROWS(TableA)),
FilTableB,INDEX(TableB,1,1):INDEX(TableB[Val-B],ROWS(TableA)),
SORTBY(FilTableB,XLOOKUP(RANK(FilValB,FilValB),RANK(TableA[Val-A],TableA[Val-A]),SEQUENCE(ROWS(FilTableB)))))

Calculated field totals not correct in PowerPivot

I have a basic data set with a ton of slicers that roughly looks like this:
Hours SpreadPerHr Spread
5.00 5.00 25.00
10.00 2.00 20.00
8.00 10.00 80.00
Where Spread is a calculated value where Spread = Hours*SpreadPerHour. The problem is, the totals for these columns follow this formula too, so it looks like this:
Hours SpreadPerHr Spread
5.00 5.00 25.00
10.00 2.00 20.00
8.00 10.00 80.00
Total: 23.00 17.00 391.00
And while the hours total up just fine, SpreadPerHour is dynamic and so Spread is as well. It is incorrect to say Total Spread = Total Hours * Total SpreadPerHour. Totals should be:
Total: 23.00 17.00 125.00
Is there a way I can make excel leave totals for Hours as-is, but sum the column for Spread instead of multiplying totals?
Here is what I think you have in your Power Pivot Model:
You have a calculated measure for Spread, which I have labeled SpreadCalc1. The problem with this is that it does the aggregation before it does the multiplication. You need this operation to be done on a row-by-row basis and then aggregated. So instead of a calculated measure, you need to create a calculated column and then sum that column.
The column I have labeled as SpreadCalc has the formula =[Hours] * [SpreadPerHr].
The calculated measure I called Spread is just Sum([SpreadCalc]). You can see there that the total is 125 as desired instead of 391.
I know this might be a bit redundant now, but I would suggest a slightly different approach.
Adding calculated columns in "small" tables is fine, but it can cause serious performance issues with large databases.
So to solve your problem, I believe the "correct" way is to use SUMX function.
It calculates the expression specifically for each row, which is exactly what you need. And it is smart as far as performance goes (no need to add calculated columns or perform any source-data manipulations).
If you use this formula (correct the name of the table / measures), you should get the desired results:
SUMX(YourTable, [Sum Hour] * [Sum SpreadPerHr])

Pulling Data in to Excel from SQL Server 2012 and formatting it

I will try and explain as best I can what i am trying to do but I am no Excel genius :-)
I have 1 Excel Sheet which we will call Template this is going to be pre-populated with data and then used offline, I am going to import a Data Set in to a tab called RawData from SQL Server, data set will be something similar to this
Description Rate Hours SellValue Item
APU 2.50 3 7.50 1
APU 2.50 4 10.00 2
APU 2.50 5 12.50 3
INS 2.50 3 7.50 1
INS 2.50 4 10.00 2
INS 2.50 5 12.50 3
There could be more or less records but no more than 7 distinct descriptions.
There is now another Tab called Report
At Position A1 will be the Title APU then underneath that I want the records with the Description APU to appear and this block will shrink and expand depending on the number of records. Then wherever the last record appears will be the next heading INS and the records associated with that description. There is one final tab called Rate and at position A1 will be a rate value, when this is changed, it will take the new rate value and re-calculate the SaleValue in RawData thus amending the figures in the Report. I am sure there are better ways to explain this but I hope someone has got the gist before I loose what hair I have left.
Thanks in advance
The easiest and powerful approach to such problems would be to use Pivot-Tables in excel. You can customize your data view better.

Populating values in Excel based on another column of values

I'm not the best with technical descriptions but please bear with me.
The task before me:
A large spreadsheet with a column of values that need to be reviewed and a different number input beside them. Unfortunately the number is not simply "value, less 15% though it's close". I will need to have a list of specific "find/replace" commands for my formula.
Example:
3.02
6.65
1.54
3.02
And I need to format it such that it says:
3.02 2.80
6.65 5.60
1.54 1.40
3.02 2.80
My idea was something along the lines of =if(A1=3.02,2.80,=if(A1=6.65,5.60,=if(A1....
Then I'd be able to just paste this formula and drag down the entire spreadsheet.
Unfortunately that didn't work and so I come to you all for help.
Please save me tons of time and figure out how I can make this spreadsheet generate it's own values!
Thanks,
Mike
I would make a little lookup table of the specific replacements:
A B
1 lookup result
2 3.02 2.8
3 6.65 5.6
4 1.54 1.4
5 3.02 2.8
And then you could set up a formula like this:
9 value result
10 3.02 =VLOOKUP(A10,A$2:B$5,2,FALSE)
11 6.65
12 1.54
13 3.02
14 1.54
And you can drag that formula down the rest of the table.
Beware of the A$2:B$5 - if your lookup table is differently-sized, it will need to change.
OR, to keep more along the lines of what you have, try a formula like this:
=if(A1=3.02,2.80,if(A1=6.65,5.60,if(A1....
The change I made was to remove the extra = before the inner IF function calls.
It is hard to guess how many different value do you have. Based on your given sample data you can use XLOOKUP() function like below if you have Excel-365.
=XLOOKUP(A1,{5.6,2.8,1.4},{5.6,2.8,1.4},"",-1)

Resources