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
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
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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.