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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
smpa01
Super User
Super User

Ensuring typesafe

how can I ensure, the function execution result returns same type as mentioned in the function?

 

let
    test_type = () as text=> "Hello",
    tbl = #table(type table [Name = text, Score = number], {{"Betty", 90.3}, {"Carl", 89.5}}),
    #"Added Custom" = Table.AddColumn(tbl, "Custom", each test_type())
    /*want to avoid doing below and the type needs to cascade from the function*/
    /*Table.AddColumn(tbl, "Custom", each test_type(), type text)*/
in
    #"Added Custom"

 

getting this

smpa01_0-1746036387709.png

desire this

smpa01_1-1746036490107.png

without requiring to do this

Table.AddColumn(tbl, "Custom", each test_type(), type text)

 @AlexisOlson @ImkeF 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

How about this?

= Table.AddColumn(tbl, "Custom", each test_type(), Value.Type(test_type()))

View solution in original post

3 REPLIES 3
AlexisOlson
Super User
Super User

How about this?

= Table.AddColumn(tbl, "Custom", each test_type(), Value.Type(test_type()))

Smashing

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Why not first define the records, then build your #table by referring to the records and the the function, and assign the text type in the #table function itself?

 

--Nate

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors