Forum Discussion

Brinki's avatar
Brinki
Frequent Visitor
1 year ago
Solved

Power Query get columns

Any idea how I can get the name & date modified columns with power query?

 

  • Brinki

    From UI, you may follow these steps,

    1. To keep only needed columns, select the columns: 'Content', 'Name', 'Date modified', right-click and choose Remove Other Columns

    2. Import file content

    1. Click the Add Column tab
    2. Choose Custom Column
    3. Name it: Data
    4. Use this formula:
    Csv.Document([Content], [Delimiter=";"])

    3. Promote headers by clicking Use First Row as Headers on the top ribbon

    4. Expand nested table

    1. In the main query, click the expand icon beside the Data column

    2. Select the columns you want to import (from your CSV conten)

9 Replies

  • Daniel29195's avatar
    Daniel29195
    Icon for Community Champion rankCommunity Champion

    Hello Brinki, 

     

    do you like removing all the columns except for these 2 columns ? if that so, simply click on shift or ctrl cant remember which one, and select with your mouse on the column name and date modified. 

    then right click on one of these 2 columns,  --> remove other columns . 

     

     

     

    let me know if this is what you want. if not ,feel free to reply to my respond. 

     

     

  • Do you really want these?  The data in those columns would then be replicated in all rows of the expanded CSV files. Depending on the number of rows in each file that can add up (although in fairness these columns will compress very well in Vertipaq) 

  • Hi Brinki 

    The other columns should still be available even if you expanded Content.

  • Brinki

    From UI, you may follow these steps,

    1. To keep only needed columns, select the columns: 'Content', 'Name', 'Date modified', right-click and choose Remove Other Columns

    2. Import file content

    1. Click the Add Column tab
    2. Choose Custom Column
    3. Name it: Data
    4. Use this formula:
    Csv.Document([Content], [Delimiter=";"])

    3. Promote headers by clicking Use First Row as Headers on the top ribbon

    4. Expand nested table

    1. In the main query, click the expand icon beside the Data column

    2. Select the columns you want to import (from your CSV conten)

  • Hi Brinki 
    Please try the below query:

    let
    // 1. Connect to SharePoint
    Source = SharePoint.Files("https://your-site.sharepoint.com/sites/your-site-name", [ApiVersion = 15]),

    // 2. Filter to specific folder
    FilteredFiles = Table.SelectRows(Source, each Text.Contains([Folder Path], "Shared Documents/FolderName/")),

    // 3. Keep only relevant columns
    SelectedColumns = Table.SelectColumns(FilteredFiles, {"Name", "Date modified", "Content"}),

    // 4. Add a column to parse CSV and promote headers
    AddTables = Table.AddColumn(SelectedColumns, "Data", each try Table.PromoteHeaders(Csv.Document([Content], [Delimiter=","])) otherwise null),

    // 5. Remove original binary Content column (optional)
    RemovedContent = Table.RemoveColumns(AddTables, {"Content"}),

    // 6. Expand the nested data tables
    ExpandedData = Table.ExpandTableColumn(RemovedContent, "Data", {"Column1", "Column2", "Column3"}), // Replace with your actual column names

    // 7. Optional: Reorder or format columns
    FinalTable = Table.SelectColumns(ExpandedData, {"Name", "Date modified", "Column1", "Column2", "Column3"}) // Customize as needed
    in
    FinalTable



     I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
     Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
     As a proud SuperUser and Microsoft Partner, we’re here to empower your data journey and the Power BI Community at large.
     Curious to explore more? [Discover here].
    Let’s keep building smarter solutions together!

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Brinki ,

    Thank you for reaching out to the Microsoft Fabric Community Forum. 

     

    If you're importing files (e.g., CSVs from SharePoint or a folder), and you want to retain file-level metadata such as Name and Date modified while expanding the file content in Power Query, the approach shared by grazitti_sapna  using M code is fully accurate and effective. It ensures:

    • The binary content is processed with Csv.Document, keeping the file metadata, which is then combined with the tabular data. The final result provides the necessary columns, with the content organized into a structured format.

    Alternatively, as demonstrated by MasonMA , the same can be achieved through the Power Query UI by:

    1. Retaining only Name, Date modified, and Content columns,
    2. Adding a custom column to parse the binary using Csv.Document,
    3. Promoting headers and expanding the resulting tables.

    As noted by danextian , metadata columns remain available even after expansion, and lbendlin  rightly points out that although metadata is repeated for each row post-expansion, Power BI’s compression engine typically handles it efficiently.

    Both the script-based and UI-driven methods provided above will meet your requirement. You can proceed confidently with either, depending on your comfort level with M code or GUI.

     

    I hope this helps resolve your issue. If you need any more assistance, please feel free to reach out.

     

    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Brinki ,

     

    I wanted to follow up on our previous suggestions. We would like to hear back from you to ensure we can assist you further.

     

    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi @Brinki ,

     

    I wanted to follow up on our previous suggestions. We would like to hear back from you to ensure we can assist you further.

     

    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Brinki ,

     

    We haven’t received an update from you in some time. Could you please let us know if the issue has been resolved?
    If you still require support, please let us know, we are happy to assist you.

     

    Thank you.