Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
RamblingFire
Regular Visitor

Csv into table

Hi, 

 

Newbie here looking for some help. 

 

I have a csv file for example with 2 sections, top let's call compliant and second section called non compliant. Each can be of any number of rows

 

Header row 

A,b,c

Header row

X,y,z

 

I'd like to transform into:

Date,Compliant,a,b,c

Date,Not Compliant,x,y,z

 

File arrives via email, power automate saves to one drive and aiming to load into power bi or dataflow. New data arrives via email to be added into table.

 

I'm stuck trying to find how to tag the rows by their section, ie tag row before header pattern and after header pattern. 

 

Any help would be great! 

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

hello, @RamblingFire one of possible ways to do this is to import csv into PQ, promote headers, find a position of non-compliant part using headers (Table.PositionOf), split your table (Split.At), add compliant / not compliant status column and combine tables back together. 

let
    csv_import = #table(
        {"h1", "h2", "h3"}, 
        {{"a", "b", "c"}, {"d", "e", "f"},
        {"h1", "h2", "h3"}, 
        {"a", "b", "c"}, {"a", "b", "c"}}
    ),
    cols = List.Buffer(Table.ColumnNames(csv_import)),
    split = Table.SplitAt(
        csv_import,
        Table.PositionOf(
            csv_import, 
            Record.FromList(cols, cols)
        )
    ),
    result = 
        Table.AddColumn(split{0}, "Status", each "Compliant") & 
        Table.AddColumn(Table.PromoteHeaders(split{1}), "Status", each "Not Compliant")
in
    result

View solution in original post

5 REPLIES 5
AlienSx
Super User
Super User

hello, @RamblingFire one of possible ways to do this is to import csv into PQ, promote headers, find a position of non-compliant part using headers (Table.PositionOf), split your table (Split.At), add compliant / not compliant status column and combine tables back together. 

let
    csv_import = #table(
        {"h1", "h2", "h3"}, 
        {{"a", "b", "c"}, {"d", "e", "f"},
        {"h1", "h2", "h3"}, 
        {"a", "b", "c"}, {"a", "b", "c"}}
    ),
    cols = List.Buffer(Table.ColumnNames(csv_import)),
    split = Table.SplitAt(
        csv_import,
        Table.PositionOf(
            csv_import, 
            Record.FromList(cols, cols)
        )
    ),
    result = 
        Table.AddColumn(split{0}, "Status", each "Compliant") & 
        Table.AddColumn(Table.PromoteHeaders(split{1}), "Status", each "Not Compliant")
in
    result

Hi AlienSx, 

 

Thanks so much for this, it looks exactly what I need. Can you share or provide me with a pointer where I can enter the above script? 

Thank you, what stands out to me is the fact that data is in the query, how would this apply to a second file with other data? 

Ahha I think I get it, the split function uses the column headers irrelevant to where they appear. The data is in the query for example and I could just reference the table name as per 2nd example in video 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.