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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

create new rows for each number of students identified in the cell 'Number of new students'

Hi,

 

I have schood data that summarises the column named 'Number of Students' as number values - See below table:

 

School IDYearSemesterYear LevelAssessment ResultsNumber of studentsAssessment Criteria Name
220161Year 1E7Reading and viewing
420172Year 2A105Reading and viewing
720183Year 3C170Reading and viewing
520194Year 4B58Reading and viewing

 

I want to create new rows for each number of students identified in the cell 'Number of new students'.

Example: If 'Number of new students' cell is '58' then create '58' new row instances of that cell.

 

The goal is to result in a single row for 1 student. Hence... 1 row represents 1 student. 

 

Appreciate the help!

 

Thanks,

Theo. 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous 

This can be done easily and best in Power Query. Place the following M code in a blank query to see the steps. Could be done in DAX as well if required

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUTIyMDQDUoZAHJmaWKQAYrgCsTkQB6UmpmTmpSsk5qUolGWmlgPZSrE60UomEH0gJUYwfSCGI8ggA1M8Os0hOi2AlDFMJ4jhDNJpboBHpylEpyWQMoHpBDGcgNjUApfGWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"School ID" = _t, Year = _t, Semester = _t, #"Year Level" = _t, #"Assessment Results" = _t, #"Number of students" = _t, #"Assessment Criteria Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"School ID", Int64.Type}, {"Year", Int64.Type}, {"Semester", Int64.Type}, {"Year Level", type text}, {"Assessment Results", type text}, {"Number of students", Int64.Type}, {"Assessment Criteria Name", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Numbers(1,[Number of students])),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Custom"})
in
    #"Removed Columns"

 

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

1 REPLY 1
AlB
Community Champion
Community Champion

Hi @Anonymous 

This can be done easily and best in Power Query. Place the following M code in a blank query to see the steps. Could be done in DAX as well if required

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUTIyMDQDUoZAHJmaWKQAYrgCsTkQB6UmpmTmpSsk5qUolGWmlgPZSrE60UomEH0gJUYwfSCGI8ggA1M8Os0hOi2AlDFMJ4jhDNJpboBHpylEpyWQMoHpBDGcgNjUApfGWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"School ID" = _t, Year = _t, Semester = _t, #"Year Level" = _t, #"Assessment Results" = _t, #"Number of students" = _t, #"Assessment Criteria Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"School ID", Int64.Type}, {"Year", Int64.Type}, {"Semester", Int64.Type}, {"Year Level", type text}, {"Assessment Results", type text}, {"Number of students", Int64.Type}, {"Assessment Criteria Name", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Numbers(1,[Number of students])),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Custom"})
in
    #"Removed Columns"

 

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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