Forum Discussion
Crear Columna con nombre de carpeta
Hola comunidad. Espero puedan ayudarme.
Tengo un conjunto de archivos referentes a movimientos de stock, un archivo para cada fecha. Estos archivos estan almacenados dentro de carpetas de acuerdo a la categoria de productos a la cual pertenecen. Al realizar la consulta quisiera agregar una columna donde indique la categoria de producto tomada de la carpeta que contiene los archivos. Lo estaba haciendo de manera manual, creando una consulta individual para cada categoria y luego haciendo una nueva consulta anexando cada una de las consultas hecha para cada categoria. Sin embargo, son mas de 8 categorias, asi que me tomaria mucho tiempo. Si se puede agregar el nombre del archivo a una columna, debe ser posible agregar parte de la ubicacion del archivo (en este caso, el nombre de la carpeta que lo contiene) a una columna de la tabla.
Espero haberme
1 Reply
- rubayatyasmin
Community Champion
Power BI doesn't provide a direct way to extract folder names when importing files. However, there is a workaround using the Power Query Editor to add the folder name as a column. Here's how:
- Click on Home > Get Data > More.
- In the Get Data window, select Folder from the File category, then click Connect.
- In the Folder dialog, provide the path to the parent directory that contains your category folders, then click OK.
- In the Folder dialog, click Edit.
- You'll be taken to the Power Query Editor. In the Content column, you should see your files listed. You'll also see the Folder Path column which includes the full path of your files.
- Select the Folder Path column, then click Split Column > By Delimiter.
- In the Split Column by Delimiter dialog, type \ in the Select or enter delimiter field (or use / if that's the delimiter in your file paths), choose Right-most delimiter, and then click OK. This will split the Folder Path column into two columns: one with the path up to the parent folder and another with the category folder name.
- Rename the new column to something like Category.
- Now, click on the double arrows in the Content column to expand and extract data from your files. You can choose which columns to import in the dialog that appears.
- Once done, click Home > Close & Apply to apply the transformations and load the data to the Power BI data model.
Now you have a column Category that indicates the product category for each row. The category is retrieved based on the folder name.