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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

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
Super User
Super User

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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