Hi all,
This is related primarily to data type problem.
Let's say I have a column which contains both number and text, and in the excel interface when i do text to columns the numbers will be treated as numbers and text will stay as text.
When in power query I have changed the data type to any and when load onto excel the cells with numbers will need to perform a text to columns to be treated as numbers. So I want to know whether this can be done in power query so don't need to perform this extra step every time it refreshes.
The number is to perform vlookup in another excel table which I currently am still working on to do the calculations in power pivot, so in the mean time it needs to be load onto an excel sheet and perform vlookup there.
Because even if the numbers are the same but one in text and one in number the vlookup still returns #N/A so if forgetting to do text to columns there might be mistakes.
Thanks in advance for helping.
Hi Eric,
So you had done split to column in Power Query, you can change column in PQ to either Text or Number depending whether field require subsequent for computation
if you use Power Query then all use PQ and not vlookup ( in fact I would recommend Index & match instead), for equivalent of vlookup in PQ will be Merge and it is quite easy and build only one time, the primary key of both table need to be same data type (Text > Text, or Number > Number
You can upload a sample worksheet and state what you want to achieve so we can help
Hi Chris,
Thank you for giving a quick reply.
Just to say that I currently have to have the result in an excel table to do further matching (vlookup or index match), so I cannot do merge queries.
You can see in the attached example what it currently shows when loaded compared to what I want (which is just one click of "text to columns" away)
And actually I now found out the problem is because my original data source is a csv file, and unlike normal excel files, in the query pane it will default to text data type (rather than "any" data type), and this causes my numbers data is considered text.
I have attached 2 identical files (1 in xlsx and 1 in csv). If you import both files in power query, you can see that csv file is defaulted to text data type, while xlsx is "any" data type; so when loaded onto excel sheet the xlsx file output have the numbers cells on the right (treated by excel as number), and the csv file output have the numbers cells on the left (treated by excel as text).
So actually my problem now is that if power query can treat csv file as "any" data type like xlsx file.
Thank you.
Hi Eric,
Like Chris said, ideally you should be doing these VLOOKUPS/INDEX&MATCH lookups in Power Query, not in the worksheet. In Power Query a lookup is called a Merge. It does exactly the same thing as the VLOOKUP, so there really is no need to ever do a VLOOKUP or INDEX&MATCH in the worksheet again. If you use the Merge technique then you should format all of the lookup columns as 'text'.
That said, if you insist on using VLOOKUPS/INDEX&MATCH, you can manually change the data type in Power Query to 'any' by typing it in the formula bar of the Changed Type step.
For example, when importing the CSV file the Changed Type step will look like this in the formula bar:
= Table.TransformColumnTypes(Source,{{"example", type text}})
Simply replace 'text' with 'any':
= Table.TransformColumnTypes(Source,{{"example", type any}})
I hope that helps.
Mynda
Hi Mynda,
Yes definitely ideally I would do this all within power query/ power pivot, but because now the calculation is done on an excel spreadsheet and I don't have time to implement it in power pivot just yet.
Actually after some googling I think it is because of the nature of CSV files that all data will be stored as text. So even like you suggested to do that change type to any, when loaded onto to excel sheet you still need a text to columns (or just double click the cell then enter) to make it interpreted as a number while if the source is in xlsx then it will be loaded as a number.
Anyway this is no big deal and I will just do text to columns in the mean time.
BTW, I have watched many of your videos and they have helped me on power query big time!
Thanks
No worries, Eric. One day when you get time you can overhaul the process to be more efficient and use Power Query. It's great to know you found my videos helpful 🙂