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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
PetrR
Regular Visitor

Custom Function Add column

Hi,

 

I have a custom function (see below a fraction of it). What I am supposed to insert in that function in order it adds a custom column to a table in which this function is invoked?

Till now, I've been getting errors such as :cannot convert value into table:

 

Thank you in advance for any help

 

 

if numberOfSlashes=2
then
Table.AddColumn(WHAT TO INSERT HERE?,
"firstDirectory", "2" ......)

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

Hi PetrR,

 

Follow this pattern:

Table.AddColumn(table as table, newColumnName as text, columnGenerator as function,  optional columnType as nullable type) as table  

Regards,

Jimmy Tao

Hi Jimmy,

thanks for your help.

I have this code (see below)

So I am supposed to set the first parameter in Table.AddColumn function as parameter? 

For example, I run this function within a table "gsc-data". If I set the parameter table to gsc-data, the Power Query reponses 

 

 

An error occurred in the ‘Query1’ query. Expression.Error: We cannot convert the value "gsc-data" to type Table.
Details:
Value=gsc-data
Type=Type

 

 

Next time, the table from whichh the function is runned might be "analytics data". So I think the table name should be a parameter, but do not how to make it work...

 

 

let

structureURL = (url,table)=> let




#"urlWithoutProtocol" =
if Text.Contains(url,"https://") = true then Text.Replace (url,"https://","")
else if Text.Contains(url,"http://") = true then Text.Replace (url,"http://","")
else url,

#"urlWithoutEndingSlash" = if Text.End(urlWithoutProtocol,1)="/" then Text.Start(urlWithoutProtocol,Text.Length(urlWithoutProtocol)-1)
else urlWithoutProtocol,

#"numberOfSlashes" = Text.Length(urlWithoutEndingSlash)-Text.Length(Text.Replace(urlWithoutEndingSlash,"/","")),

 

 

#"firstDirectory"= if numberOfSlashes=1 then Text.Middle(urlWithoutEndingSlash,Text.PositionOf(urlWithoutEndingSlash,"/"),100)
else

if numberOfSlashes=2
then
Table.AddColumn(table as table, "firstDirectory", "2") as table
else ""

 

in #"firstDirectory"

 

in #"structureURL"

 

 

 

Thanks

RP

Hi PetrR,

 

Is "gsc-data" an exist table or the name of table you want to create? Could you share a screenshot of tables you have?

 

Regards,

Jimmy Tao

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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