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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
smpa01
Community Champion
Community Champion

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: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================
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: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.