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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
FelipeJaworoski
Frequent Visitor

Table.Split by a delimeter

So, I think my question is quite simple, but I've tried to search for an answer on the web and couldn't find anything.

 

Basically, I want to use the function Table.Split but with the seccond argument defined by the first time a value appears on my first column.

 

For example, i have the following table:

 

FelipeJaworoski_0-1673615516173.png

(sorry for the print but i wasn't able to add a table because of a invalid HTML problem)

 

And goes like this until December. I know that I can use the number 34 on the seccond argument and it will works. But in case someone add a new project, the number changes. So i want to make the split by the first null value that appears on the first column or by the Total row.

 

Can anyone help me, please?!

1 ACCEPTED SOLUTION

I suggest

  •  Add an Index Column (zero-based)
  • Use List.PositionOf to obtain the position of all the nulls, as well as the number of rows in the table
  • Use List.Generate to generate the individual tables by using Table.SelectRows relative to the Index column
  • Remove the Index column within the List.Generate function

 

 

...
    #"Added Index" = Table.AddIndexColumn(#"Previous Step", "Index", 0, 1, Int64.Type),

    n = List.PositionOf(#"Added Index"[Name],null,Occurrence.All) & {Table.RowCount(#"Added Index")},

    #"Split Table" = List.Generate(
        ()=>[t=Table.SelectRows(#"Added Index", (tb)=> tb[Index]<n{0}), idx=0],
        each [idx] < List.Count(n),
        each [t=Table.SelectRows(#"Added Index", (tb)=>tb[Index] > n{[idx]} and tb[Index] < n{[idx]+1}), idx=[idx]+1],
        each Table.RemoveColumns([t],"Index"))
in
    #"Split Table"

 

 

If, as you imply in your question, you only want the FIRST split, then just use:

 

Table.Split(#"Previous Step", List.PositionOf(#"Previous Step"[Name], null, Occurrence.First)){0}

 

View solution in original post

4 REPLIES 4
watkinnc
Super User
Super User

You can duplicate your source table and add an index column starting with (1). Then use Table.SelectRows to select only rows with null in the first column. At the end of that formula, add [Index]{0} to get the Index number of that row, which you can use for the parameter in Table.SplitAt(PriorStepOrTableName, NameOfTheQueryWeJustMade)

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
ppm1
Solution Sage
Solution Sage

May I ask why you want to split your table up? Usually it is better to append tables to simplify analysis/visualization. This would complicate your data model and make your DAX measures more complex.

 

Pat

Microsoft Employee

I suggest

  •  Add an Index Column (zero-based)
  • Use List.PositionOf to obtain the position of all the nulls, as well as the number of rows in the table
  • Use List.Generate to generate the individual tables by using Table.SelectRows relative to the Index column
  • Remove the Index column within the List.Generate function

 

 

...
    #"Added Index" = Table.AddIndexColumn(#"Previous Step", "Index", 0, 1, Int64.Type),

    n = List.PositionOf(#"Added Index"[Name],null,Occurrence.All) & {Table.RowCount(#"Added Index")},

    #"Split Table" = List.Generate(
        ()=>[t=Table.SelectRows(#"Added Index", (tb)=> tb[Index]<n{0}), idx=0],
        each [idx] < List.Count(n),
        each [t=Table.SelectRows(#"Added Index", (tb)=>tb[Index] > n{[idx]} and tb[Index] < n{[idx]+1}), idx=[idx]+1],
        each Table.RemoveColumns([t],"Index"))
in
    #"Split Table"

 

 

If, as you imply in your question, you only want the FIRST split, then just use:

 

Table.Split(#"Previous Step", List.PositionOf(#"Previous Step"[Name], null, Occurrence.First)){0}

 

Thank you!

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors