Index match equivalent in Access

Kobierok

New Member
Joined
Jan 12, 2016
Messages
3
Hi All,

Im trying to create a query in Access which in fact is replication of index match excel function:

I have a source table

ObjectDiso**** 1Diso**** 2Diso**** 3
X1%2%4%
Y3%1%2%
Z5%0%1%

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>

and would like to create a query which would feed another table

ObjectTYPE%
XDiso**** 11%
XDiso**** 2
XDiso**** 3
YDiso**** 1
YDiso**** 2
YDiso**** 3
ZDiso**** 1
ZDiso**** 2
ZDiso**** 3

<colgroup><col><col><col></colgroup><tbody>
</tbody>


in excel I would use index match, but dont know how to proceed in access as all typical relation type queries failed.
Is anyone dealt with such an issue and could suggest any solution?


Regards,

Karolina
 
In database terms, adding data (records/rows) is cheap, quick, and efficient.
Adding new fields is cumbersome, and could involve you having to update a bunch of different things.

So in your example, you may only have 20 records, but you have 52 fields!!!
What happens when you need to add more countries?
You would then need to add more fields, and then probably rewrite all your queries, reports, forms, and extracts.

If you choose the normalized model I suggested, if you have to add more countries, you do not need to add any new fields to your table. Simply add more rows of data (adding data instead of fields is always preferrable).
On top of that, in order to get the information out that you want, you would need to create a Union query like Alan showed up in post 3. Only, it will be much longer than that.
If you look at the structure:
Rich (BB code):
SELECT table3.Object, "Diso**** 1" AS Type, table3.[Diso**** 1] AS [Percent]
FROM table3;
UNION
SELECT table3.Object, "Diso**** 2" AS Type, table3.[Diso**** 2] AS [Percent]
FROM table3;
UNION
SELECT table3.Object, "Diso**** 3" AS Type, table3.[Diso**** 3] AS [Percent]
FROM table3;
notice how the pattern repeats (I show with different colors).

You would need one section for each of your Countries. So while this query has 3 sections, yours would have 50!
And anytime you added more Countries, you would need to add additional sections (there is that ongoing maintenance I mentioned earlier).
And quite frankly, I am not sure how fast a Union query of 50 different Countries will run. It could be a slow query.

I was very much in the same place you are in right now when I had to create my first database (I was very Excel proficient, but new to Access at the time). I had a similar situation where I had 20 investment options, so at first I created 20 fields. It was an absolute nightmare to work with! Even seemingly simple tasks became cumbersome and difficult. Then someone helped me out and told me I had to re-design the tables to follow the rules of normalization. It was a big undertaking (because I had already created many queries, forms, and reports around it), but once I did, everything fell into place, and I was now able to do everything I wanted without pulling out the rest of my hair.

A key thing to understand for those new to Access and relational databases is that it is very different from Excel. You really cannot approach it with an Excel spreadsheet state-of-mind.
You need to learn about relational databases, and how to design them (especially the Rules of Normalization). If you don't, it will probably cause you nothing but continued aggravation.
Trust me, I have been there.
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Tks again @Joe4! Really useful information! Then, I'm receiving the date as i said... 20 rows and 50 countries every 6 month. Do you have any solution on how to transform the data i'm receiving in the format you recommend? i mean, faster..no manual work and than to append the date to a table to be used as source for the entire database....
 
Upvote 0
Is the file coming over in Excel format?

If it were me, I would probably create a little Excel macro to convert the data file in the format that they are sending it to the format that I should you.
Then import that converted file into Access.

Alternatively, if it were a text file, you probably could create an Access VBA procedure that would read throught the data table and write the data directly to the table.
A bit more complex to create, but then bypasses the need for Excel.

Either way, once you create this conversion process, it should be good to go and you shouldn't have need to update it (unless they totally changed the format of the file).
 
Upvote 0
Yes, the file is coming over in excel format. I will try to create a macro for that.
 
Upvote 0
Yes, the file is coming over in excel format. I will try to create a macro for that.
Great!

If you need help, you can post a question over in the "Excel Questions" forum and someone can help you with that (I probably can, if I see it).
Just be sure to include the exact format, since that is critical, and you will want to be sure to mention that number of countries could grow in the future.
You may also want to create a link back to this thread, if anyone questions why you want to do this.
 
Upvote 0
I would normalize the data as Joe has suggested using Power Query. Here is the Mcode to make that happen

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Model", type text}, {"Austria", type text}, {"Germany", type text}, {"UK", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID", "Model"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Country"}})
in
    #"Renamed Columns"

IDModelAustriaGermanyUKIDModelCountryValue
1LaptopS$2.00$7.00$11.001LaptopSAustria$2.00
2LaptopM$3.00$5.00$8.001LaptopSGermany$7.00
3DesktopE$5.00$9.00$10.001LaptopSUK$11.00
4DesktopE$12.00$14.00$7.002LaptopMAustria$3.00
5LaptopM$6.00$15.00$17.002LaptopMGermany$5.00
2LaptopMUK$8.00
3DesktopEAustria$5.00
3DesktopEGermany$9.00
3DesktopEUK$10.00
4DesktopEAustria$12.00
4DesktopEGermany$14.00
4DesktopEUK$7.00
5LaptopMAustria$6.00
5LaptopMGermany$15.00
5LaptopMUK$17.00
 
Upvote 0

Forum statistics

Threads
1,221,521
Messages
6,160,301
Members
451,637
Latest member
hvp2262

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