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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Desyn
Regular Visitor

Referring to column by index position when using Group By

I'm really stuck with this one, I'd massively appreciate any help.

 

I have a table with employees in column 0, and then data for each week in each subsequent column. These columnns are named with the date, as shown below:

 

Employee2023 24-Nov2023 01-Dec2023 08-Dec2023 15-Dec
Jack2284
Jack7981
Jack1351
Amy7291
Amy5723
Amy5546

 

I need to produce a table with a single row for each employee, and the sum of each week for that employee in the same row, as shown below:

 

EmployeeWeek 1Week 2Week 3Week 4
Jack1014216
Amy17141510

 

I believe Group By is the best function for this. If I use the function (just for the first week to begin with), it works. The code looks like this:

 

= Table.Group(#"Changed Type", {"Employee"}, {{"Week 1", each List.Sum([#"2023 24-Nov"]), type nullable number}})

 

The thing is, I don't want to refer to the date columns by their name, as they will change each week when a new report is read in.

 

I have tried using the following code to produce this table using column index position (for just the first week to begin with), but it doesn't work.

 

Table.Group(#"Changed Type", {"Employee"}, {{"Week 1", each List.Sum(Table.ColumnNames(#"Changed Type"){1}), type nullable number}})

 

I get the following error:

Desyn_0-1701361688496.png

 

If anyone could help that would be great!

 

1 ACCEPTED SOLUTION
TheoC
Super User
Super User

Hi @Desyn 

 

You will need to do a bit of transformation before attempting to do what you are doing:

 

1. Unpivot all date columns so that there are two values in your table (Dates and Values) by selecting Employee column and "unpivot other columns".

2. Then use Group by sum values. 

 

That should give you the output you are after (hopefully).

 

Theo 🙂

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

View solution in original post

1 REPLY 1
TheoC
Super User
Super User

Hi @Desyn 

 

You will need to do a bit of transformation before attempting to do what you are doing:

 

1. Unpivot all date columns so that there are two values in your table (Dates and Values) by selecting Employee column and "unpivot other columns".

2. Then use Group by sum values. 

 

That should give you the output you are after (hopefully).

 

Theo 🙂

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors