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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
msksenthil
Helper III
Helper III

M Code Recursive function dynamic column reference

I would like to try dynamic expanding columns in M code.

 

The code is:

fxFactorial = (RowCount as number, Tnumber as number, tbl as table) =>
let
displayname = "disPath" & Text.From(Tnumber),
childrenname = "children" & Text.From(Tnumber),
prevchildname = "children" & Text.From(Tnumber-1) ,
prevstep = tbl ,
Source2 = Table.ExpandListColumn( prevstep, prevchildname),
#"Added disPath2" = Table.AddColumn(Source2, displayname, each Record.Field(prevchildname,"displayPath") ),
#"Added children2" = Table.AddColumn(#"Added disPath2", childrenname, each try Record.Field([children1],"children") otherwise null ),
ColRowCount = List.NonNullCount( #"Added children2"[children2]),
titlenumber = Tnumber + 1,
subresult = if titlenumber > 2 then @fxFactorial(ColRowCount, titlenumber, #"Added children2") else #"Added children2"
in
#"Added disPath2"

 

But, I'm getting an error stating like We cannot convert the value "children1" to Record

 

 

Much appreciated it if someone showed some light on this query.

1 REPLY 1
mahoneypat
Microsoft Employee
Microsoft Employee

You are using the prevchildname variable (a text value) in a function that expects a record (Record.Field).

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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