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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.