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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Mary78
Helper II
Helper II

Building Field Parameters using Tabular Editor 2

Hi all

 

I'm trying to build Field Parameters in Tabular editor 2.

 

As shown here:

https://p3adaptive.com/completing-the-set-up-field-parameters-using-tabular-editor/

 

Issue is that I don't get any columns when I have added the dax code for the calculated table. 

I'm pretty sure code is correct I've even generated it using desktop and pasted it to be sure.

 

 

1 ACCEPTED SOLUTION

Ok, I found a solution for this, don´t know rotsource for issue but now I use this to create Field Parameters in Tabular Editor 2 and deploy them to existing Semantic model i Services.

Pop script below in to script editor select measures or columns to include and hitt run script

And of course big thanks to who ever created the script and shared it, Mark Beedle?  ❤️

// Before running the script, select the measures or columns that you
// would like to use as field parameters (hold down CTRL to select multiple
// objects). Also, you may change the name of the field parameter table
// below. NOTE: If used against Power BI Desktop, you must enable unsupported
// features under File > Preferences (TE2) or Tools > Preferences (TE3).
var name = "Parameter";

if(Selected.Columns.Count == 0 && Selected.Measures.Count == 0) throw new Exception("No columns or measures selected!");

// Construct the DAX for the calculated table based on the current selection:
var objects = Selected.Columns.Any() ? Selected.Columns.Cast<ITabularTableObject>() : Selected.Measures;
var dax = "{\n " + string.Join(",\n ", objects.Select((c,i) => string.Format("(\"{0}\", NAMEOF('{1}'[{0}]), {2})", c.Name, c.Table.Name, i))) + "\n}";

// Add the calculated table to the model:
var table = Model.AddCalculatedTable(name, dax);

// In TE2 columns are not created automatically from a DAX expression, so
// we will have to add them manually:
var te2 = table.Columns.Count == 0;
var nameColumn = te2 ? table.AddCalculatedTableColumn(name, "[Value1]") : table.Columns["Value1"] as CalculatedTableColumn;
var fieldColumn = te2 ? table.AddCalculatedTableColumn(name + " Fields", "[Value2]") : table.Columns["Value2"] as CalculatedTableColumn;
var orderColumn = te2 ? table.AddCalculatedTableColumn(name + " Order", "[Value3]") : table.Columns["Value3"] as CalculatedTableColumn;

if(!te2) {
// Rename the columns that were added automatically in TE3:
nameColumn.IsNameInferred = false;
nameColumn.Name = name;
fieldColumn.IsNameInferred = false;
fieldColumn.Name = name + " Fields";
orderColumn.IsNameInferred = false;
orderColumn.Name = name + " Order";
}
// Set remaining properties for field parameters to work
// See: https://twitter.com/markbdi/status/1526558841172893696
nameColumn.SortByColumn = orderColumn;
nameColumn.GroupByColumns.Add(fieldColumn);
fieldColumn.SortByColumn = orderColumn;
fieldColumn.SetExtendedProperty("ParameterMetadata", "{\"version\":3,\"kind\":2}", ExtendedPropertyType.Json);
fieldColumn.IsHidden = true;
orderColumn.IsHidden = true;

View solution in original post

6 REPLIES 6
Fowmy
Super User
Super User

@Mary78 

Please check, you need to first change the Name Inferred in the properties from ‘True’ to ‘False’ for each of the three columns.


Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Could Issue be That I use Tabular Editor 2 and not 3?

 

Or maby a compatibility level issue?

Problem is that I don't get any columns to change properties on.

I have the calculated tabel but it dosen't have any columns.

@Mary78 

Sharing a dummy Power BI file representing your scenario would be beneficial. You can save the Power BI file on Google Drive or any other cloud storage platform and provide the link here. Kindly ensure that permission is granted to open the file.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Ok, I found a solution for this, don´t know rotsource for issue but now I use this to create Field Parameters in Tabular Editor 2 and deploy them to existing Semantic model i Services.

Pop script below in to script editor select measures or columns to include and hitt run script

And of course big thanks to who ever created the script and shared it, Mark Beedle?  ❤️

// Before running the script, select the measures or columns that you
// would like to use as field parameters (hold down CTRL to select multiple
// objects). Also, you may change the name of the field parameter table
// below. NOTE: If used against Power BI Desktop, you must enable unsupported
// features under File > Preferences (TE2) or Tools > Preferences (TE3).
var name = "Parameter";

if(Selected.Columns.Count == 0 && Selected.Measures.Count == 0) throw new Exception("No columns or measures selected!");

// Construct the DAX for the calculated table based on the current selection:
var objects = Selected.Columns.Any() ? Selected.Columns.Cast<ITabularTableObject>() : Selected.Measures;
var dax = "{\n " + string.Join(",\n ", objects.Select((c,i) => string.Format("(\"{0}\", NAMEOF('{1}'[{0}]), {2})", c.Name, c.Table.Name, i))) + "\n}";

// Add the calculated table to the model:
var table = Model.AddCalculatedTable(name, dax);

// In TE2 columns are not created automatically from a DAX expression, so
// we will have to add them manually:
var te2 = table.Columns.Count == 0;
var nameColumn = te2 ? table.AddCalculatedTableColumn(name, "[Value1]") : table.Columns["Value1"] as CalculatedTableColumn;
var fieldColumn = te2 ? table.AddCalculatedTableColumn(name + " Fields", "[Value2]") : table.Columns["Value2"] as CalculatedTableColumn;
var orderColumn = te2 ? table.AddCalculatedTableColumn(name + " Order", "[Value3]") : table.Columns["Value3"] as CalculatedTableColumn;

if(!te2) {
// Rename the columns that were added automatically in TE3:
nameColumn.IsNameInferred = false;
nameColumn.Name = name;
fieldColumn.IsNameInferred = false;
fieldColumn.Name = name + " Fields";
orderColumn.IsNameInferred = false;
orderColumn.Name = name + " Order";
}
// Set remaining properties for field parameters to work
// See: https://twitter.com/markbdi/status/1526558841172893696
nameColumn.SortByColumn = orderColumn;
nameColumn.GroupByColumns.Add(fieldColumn);
fieldColumn.SortByColumn = orderColumn;
fieldColumn.SetExtendedProperty("ParameterMetadata", "{\"version\":3,\"kind\":2}", ExtendedPropertyType.Json);
fieldColumn.IsHidden = true;
orderColumn.IsHidden = true;

Great, this is a link to the .bim that I´ve created from the published semantic model.
calc table  Measures 2 is created using Desktop and workes fine.
calc table  Measures 3 is created using Tabular editor 2 and I´m nor getting any columns.
Compatability level is 1550
On diff i find in table properties between measure 2 and measure 3 is that Measure 2 has 1 annotaion and measure 3 has 0. Trid copying this from 2 to 3 but no change

 

https://drive.google.com/file/d/1YBnDlESD--XwfKwxA6oEMbd9xi_wrJ8Y/view?usp=sharing

 

And .pbix

https://drive.google.com/file/d/1S0Jybu_Sn-N9C2ArBnQtMUjS4YBqkEmd/view?usp=sharing

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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