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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Thoughtknotseer
Regular Visitor

SelectRows apply to same column cause cyclic reference

Hi

 

I have a table.

IDExamScore

1

A50
2A60
3A40
4B30
5B20
6B40

 

Then I hope to add to prepare like below column for using post analysis.

IDExamScoreExamBest

1

A5060
2A6060
3A4060
4B3040
5B2040
6B4040

 

So I write below expression.

= Table.AddColumn(Filtered, "Custom", List.Max(Table.SelectRows(Scores, (r)=>[Exam]=r[Exam])[Score]))

But this expression cause expression.error a cyclic reference was encountered , How can I avoid?

 

# Sorry for my poor English, plaese reply me any correction.

1 ACCEPTED SOLUTION
m_alireza
Solution Specialist
Solution Specialist

Hi @Thoughtknotseer ,

You can use the Group by Function in Power Query to achieve your desired result. 

Copy the query below in advanced editor to see steps: 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYlMDpVidaCUjKNcMwjWGck0gXBMg0wmIjSFcUyjXCMI1g3JBimMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Exam = _t, Score = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Exam", type text}, {"Score", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Exam"}, {{"MaxScore", each List.Max([Score]), type nullable number}, {"AllRows", each _, type table [ID=nullable number, Exam=nullable text, Score=nullable number]}}),
    #"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"ID", "Score"}, {"ID", "Score"})
in
    #"Expanded AllRows"

View solution in original post

5 REPLIES 5
Thoughtknotseer
Regular Visitor

@m_alireza 

 

Really Thank you!! Table.Group is what I looking for.

 

Sorry but can I ask additional question?

Now I hope to query another column. Example table is below.

IDExamExamDateScore

1

A150
2A260
3A340
4B130
5B220
6B340

 

I also hope to get below column.

IDExamExamDateScoreBestScoreBestDate

1

A150602
2A260602
3A340602
4B130403
5B220403
6B340403

 

I was confused I suddenly ordered to use PQ at work. Really thank you for your support.

NewStep= let GpMx=Table.Buffer(Table.Group(PreviousStepName,"Exam",{"n",each List.MaxN(Table.ToRows([[Score],[ExamDate]]),1,each _{0}){0}})) in #table(Table.ColumnNames(PreviousStepName)&{"BestScore","BestDate"},List.Transform(Table.ToRows(PreviousStepName),each _&GpMx{[Exam=_{1}]}[n]))

Thank you! I keep study to understand.

m_alireza
Solution Specialist
Solution Specialist

Hi @Thoughtknotseer ,

You can use the Group by Function in Power Query to achieve your desired result. 

Copy the query below in advanced editor to see steps: 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYlMDpVidaCUjKNcMwjWGck0gXBMg0wmIjSFcUyjXCMI1g3JBimMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Exam = _t, Score = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Exam", type text}, {"Score", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Exam"}, {{"MaxScore", each List.Max([Score]), type nullable number}, {"AllRows", each _, type table [ID=nullable number, Exam=nullable text, Score=nullable number]}}),
    #"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"ID", "Score"}, {"ID", "Score"})
in
    #"Expanded AllRows"

Hi, @m_alireza ,

I have similar issue and using Table.Group function and still facing issue.

Dwisha_S_0-1695310921288.png

 

I am looking to get the Average of forecast coloumn for Current Week to 6th Week Group by InternalID and I have tried multiple attempts to format the function.

1) 
let MINDATE = Date.WeekOfYear(DateTime.LocalNow()), Maxdate = MINDATE + 5, Source = #"Demand Fcst Raw Outputs", FilteredTable = Table.Group( Table.SelectRows(Source, each [Week Number] >= MINDATE and [Week Number] <= Maxdate), {"Internal ID"}, {{"TotalForecast", each List.Sum([Forecast]), type number}} ), FinalTable = Table.AddColumn(FilteredTable, "Test", each [TotalForecast] / 6) in FinalTable

2) let
FilteredTable = Table.Group(#"Demand Fcst Raw Outputs (2)", [Internal ID],List.Sum[Forecast],[Week Number]=Date.WeekOfYear(DateTime.LocalNow()) and [Week Number]<=Date.WeekOfYear(DateTime.LocalNow())+5),
FinalTable = Table.AddColumn(FilteredTable, "Test", each [TotalForecast] / 6)
in
FinalTable

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.