DMAX with multiple conditions in one column

CTOM

New Member
Joined
Sep 26, 2005
Messages
12
I am trying to transfer data one worksheet into another based on a set of conditions. I am using DMAX to select the largest value out of 4 or 5 values from one day and than match that to the same date in a column in my report worksheet. Based on my understanding of Database functions, I would have to have a column label repeated before every date in my report worksheet. Is this true?

I am also looking into index match scenarios, but I don't think I can get the max function to work. Any advice would be appreciated.

Thanks

DATE PCE
9/22/2005 58.744
9/22/2005 56.54
9/22/2005 52.948
9/22/2005 60.904
9/22/2005 76.468
9/23/2005 89.654
9/23/2005 85.298
9/23/2005 76.876
9/23/2005 92.414
9/23/2005 126.566
9/23/2005 210.266
9/23/2005 185.16
9/24/2005 49.462
9/24/2005 557.276
9/24/2005 329.208
9/24/2005 378.488
9/24/2005 409.196
9/24/2005 414.534
9/24/2005 426.646
9/24/2005 482.054

Report
9/24/05 MAX value of PCE (557)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi CTOM:

I hope the following helps!
y051104h1.xls
ABCDE
1dataBaseDATE
2criterion09/24/2005
3result
4
5DATEPCE557.276
609/22/200558.744
709/22/200556.54
809/22/200552.948
909/22/200560.904
1009/22/200576.468
1109/23/200589.654
1209/23/200585.298
1309/23/200576.876
1409/23/200592.414
1509/23/2005126.566
1609/23/2005210.266
1709/23/2005185.16
1809/24/200549.462
1909/24/2005557.276
2009/24/2005329.208
2109/24/2005378.488
2209/24/2005409.196
2309/24/2005414.534
2409/24/2005426.646
2509/24/2005482.054
26
Sheet3
 
Upvote 0
DMAX mulitple condition clarification

Thanks Yogi for your suggestion. But I don't think that solves my problem.

I have report page with fixed dates, so I cannot change the layout. The format is
Date PCE
9/22/05 ?
9/23/05 ?
9/24/05 ?
9/25/05 ?
etc..

I can get a value using DMAX for 9/22/05, just not sure how to do it for the rest. Hopefully this clarifies the problem.

Thanks again
 
Upvote 0
Re: DMAX mulitple condition clarification

CTOM said:
Thanks Yogi for your suggestion. But I don't think that solves my problem.

I have report page with fixed dates, so I cannot change the layout. The format is
Date PCE
9/22/05 ?
9/23/05 ?
9/24/05 ?
9/25/05 ?
etc..

I can get a value using DMAX for 9/22/05, just not sure how to do it for the rest. Hopefully this clarifies the problem.
Hi CTOM:

I am not sure what you mean, and I did not say you have to change your layout. Anyway, the following DataTable Solution might help ...
y051104h1.xls
ABCDEF
1dataBaseDataTable Solution
2criterion
3result
4DATEPCE
5DATEPCE09/22/200576.468
609/22/200558.74409/23/2005210.266
709/22/200556.5409/24/2005557.276
809/22/200552.948
909/22/200560.904
1009/22/200576.468
1109/23/200589.654
1209/23/200585.298
1309/23/200576.876
1409/23/200592.414
1509/23/2005126.566
1609/23/2005210.266
1709/23/2005185.16
1809/24/200549.462
1909/24/2005557.276
2009/24/2005329.208
2109/24/2005378.488
2209/24/2005409.196
2309/24/2005414.534
2409/24/2005426.646
2509/24/2005482.054
26
Sheet3


Let me know how it goes!
Thanks again
 
Upvote 0
Thanks Yogi - Its looks like you have solved the problem. Unfortunatly, I can't see the formula. I'm not sure if I caused the error or what. But everytime I click on the hyperlink for E6, I get an error on page notice. Would you mind including that formula on a post outside of a table? I am very curious to find out where I was going wrong. Thanks again.

Chris
 
Upvote 0
CTOM said:
Thanks Yogi - Its looks like you have solved the problem. Unfortunatly, I can't see the formula. I'm not sure if I caused the error or what. But everytime I click on the hyperlink for E6, I get an error on page notice. Would you mind including that formula on a post outside of a table? I am very curious to find out where I was going wrong. Thanks again.

Chris
Hi Chris:

formula in cell E5 is ... =DMAX(A5:B25,2,D4:D5)

If you have worked with DataTable feature before, with the formula in cell E5 you are all set.

However, in case you have not worked with DataTable feature before let me reproduce my illustration and let us delineate it step by step.
y051104h1.xls
ABCDEF
1dataBaseDataTable Solution
2criterion
3result
4DataTableDATEPCE
5DATEPCE09/22/200576.468
609/22/200558.74409/23/2005210.266
709/22/200556.5409/24/2005557.276
809/22/200552.948
909/22/200560.904
1009/22/200576.468
1109/23/200589.654
1209/23/200585.298
1309/23/200576.876
1409/23/200592.414
1509/23/2005126.566
1609/23/2005210.266
1709/23/2005185.16
1809/24/200549.462
1909/24/2005557.276
2009/24/2005329.208
2109/24/2005378.488
2209/24/2005409.196
2309/24/2005414.534
2409/24/2005426.646
2509/24/2005482.054
26
Sheet3


My DataBase is A5:B25. I am after producing the result in cell E5, which I do by using DMAX function using the DataBase and Criterion in cells D4:D5 ... for this formula in cell D5 is =A6; in cell D4 is required Label DATE, and in cell E4 is the optional label PCE

Now that we have the formula in cell E5, I am going to create my DataTable which will create result similar to that in cell E5 with other values as in cell D5.

For this I make the entries 09/23/2005 in cell D6 and 09/24/2005 in cell D7 (in a larger problem these could have been created using Advanced Filter and the DataBase). Now for making the DataTable,

1) select the cells D5:E7
2) invoke Data|Table
3) in the DialogBox that pops up, enter $D$5 in the TextBox for Column_Input_Cell
4) then click on OK
5) if you see the cells E6 and E7 populated with values 210.266 and 557.276 ... Success! ... if not let us go back to step 1 to mke sure every thing has been done correctly.

By the way you will not see any formulas in cells E6 and E7 ... you will see {=TABLE(,D5)}

Good Luck!
 
Upvote 0
Further to Yogi's suggested Formula + Datatable way,

Here is a bit simply formula way, and can obtain the same result ,

In Cell E5, enter the formula and copies down to E7 :

=DMAX(INDEX($A$5:$A$25,MATCH(D5,$A$6:$A$25,0)):$B$25,2,D4:D5)

Hope that helps
 
Upvote 0
bosco_yip said:
Further to Yogi's suggested Formula + Datatable way,

Here is a bit simply formula way, and can obtain the same result ,

In Cell E5, enter the formula and copies down to E7 :

=DMAX(INDEX($A$5:$A$25,MATCH(D5,$A$6:$A$25,0)):$B$25,2,D4:D5)

Hope that helps
Hi bosco_yip:

I could not get the corect results using your formula. Would you please check and advise ...

1) if the formula does indeed give correct results,
2) how is the simply formula based approach you presented simpler than the formula I used in cell E5 and DataTable approach?
 
Upvote 0
Hi Yogi,

My computer (Office XP) can give me the correct results, different Excel version problem ??

I am using your 2nd table :
1. database at cells A5:B25, with heading A5="DATE", B5="PCE", datas at A6:B25.
2. D4="DATE"
3. D5:D7={9/22/2005, 9/23/2005,9/24/2005}

Then, the formula in cells E5:E7 :

E5 =DMAX(INDEX($A$5:$A$25,MATCH(D5,$A$6:$A$25,0)):$B$25,2,D4:D5)
>> =DMAX($A$5:$B$25,2,D4:D5)
>> =76.468

E6 =DMAX(INDEX($A$5:$A$25,MATCH(D6,$A$6:$A$25,0)):$B$25,2,D5:D6)
>> =DMAX($A$10:$B$25,2,D5:D6)
>> =210.266

E7 =DMAX(INDEX($A$5:$A$25,MATCH(D7,$A$6:$A$25,0)):$B$25,2,D6:D7)
>> =DMAX($A$17:$B$25,2,D6:D7)
>> =557.276

Regards
Bosco Yip
 
Upvote 0
bosco_yip said:
Hi Yogi,

My computer (Office XP) can give me the correct results, different Excel version problem ??

I am using your 2nd table :
1. database at cells A5:B25, with heading A5="DATE", B5="PCE", datas at A6:B25.
2. D4="DATE"
3. D5:D7={9/22/2005, 9/23/2005,9/24/2005}

Then, the formula in cells E5:E7 :

E5 =DMAX(INDEX($A$5:$A$25,MATCH(D5,$A$6:$A$25,0)):$B$25,2,D4:D5)
>> =DMAX($A$5:$B$25,2,D4:D5)
>> =76.468

E6 =DMAX(INDEX($A$5:$A$25,MATCH(D6,$A$6:$A$25,0)):$B$25,2,D5:D6)
>> =DMAX($A$10:$B$25,2,D5:D6)
>> =210.266

E7 =DMAX(INDEX($A$5:$A$25,MATCH(D7,$A$6:$A$25,0)):$B$25,2,D6:D7)
>> =DMAX($A$17:$B$25,2,D6:D7)
>> =557.276

Regards
Bosco Yip

Bosco,

Your results are correct (on Excel 2003), but they need an explanation for the label DATE in the criteria range is not available during the second and the third application of the DMAX formula and yet we get correct results.

Facts:

[1] Dates are in ascending order.

[2] The INDEX bit re-computes a subrange that the formula treates as the database range.

For the formula in E5, that is:

=DMAX(INDEX($A$5:$A$25,MATCH(D5,$A$6:$A$25,0)):$B$25,2,D4:D5)

the database is:

{"DATE","PCE";38617,58.744;38617,56.54;38617,52.948;38617,60.904;38617,76.468;...}

the criteria range is:

{"DATE";38617}

For the formula in E6 when E5 is copied down, that is:

=DMAX(INDEX($A$5:$A$25,MATCH(D6,$A$6:$A$25,0)):$B$25,2,D5:D6)

the database is:

{38617,76.468;38618,89.654;38618,85.298;38618,76.876;38618,92.414;...}

the criteria range is:

{38617;38618}

The way you invoked INDEX includes the last occurrence of 38617. Excel happily accepts 38617,76.468 as labels of the database and 38617 as label in the Criteria range. This is strange because Excel would ordinarily complain about using numbers as field names in a database-like settings like lists.

Obviously, all this happens again when the formula is copied to E7:

=DMAX(INDEX($A$5:$A$25,MATCH(D7,$A$6:$A$25,0)):$B$25,2,D6:D7)

with as database: {38618,185.16;38619,49.462;38619,557.276;...}

and as criteria range: {38618;38619}

All this can be replicated with a database in which the condition range consists of text values and this range is sorted in ascending order.
Book11
ABCDE
4NameTotal
5NameValue229.136
6a58.744b328.296
7a56.54c1221.144
8a52.948d2440.126
9a60.904
10b76.468
11b89.654
12b85.298
13b76.876
14c92.414
15c126.566
16c210.266
17c185.16
18c49.462
19c557.276
20d329.208
21d378.488
22d409.196
23d414.534
24d426.646
25d482.054
Sheet2


E5, copied down:

=DSUM(INDEX($A$5:$A$25,MATCH(D5,$A$6:$A$25,0)):$B$25,2,D4:D5)

Database & Criteria range:

For the formula in E5:

{"Name","Value";"a",58.744;"a",56.54;"a",52.948;"a",60.904;...}

{"Name";"a"}

For the formula in E6:

{"a",60.904;"b",76.468;"b",89.654;"b",85.298;"b",76.876;"c",92.414;...}

For the formula in E7:

{"b",76.876;"c",92.414;"c",126.566;"c",210.266;"c",185.16;"c",49.462;"c",557.276;...}

{"b";"c"}

For the formula in E8:

{"c",557.276;"d",329.208;"d",378.488;"d",409.196;"d",414.534;...}

{"c";"d"}

Recap:

When the database is sorted, one can calculate a subrange such that its first item can serve as a label along with a sorted criteria range: Thus, the same item appear as label both in database and in criteria range.

Does this indicate a bug in Excel? I don't think so although accepting numbers as labels here is inconsistent with other database-like settings, an issue MS should look into.
 
Upvote 0

Forum statistics

Threads
1,224,395
Messages
6,178,348
Members
452,841
Latest member
GenAkaman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top