This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Add ability to Add a Field Parameter table #541
Comments
While I agree this should be a built-in feature, the short term solution is the following script (tested and works in both TE2 and TE3!): // 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; |
Thanks for providing this... what about updating an existing field parameter? What would be the code to drop/add a field parameter table or is there a way to "update" and existing FP? |
There is a System.NullReferenceException error on line 36 (GroupByColumn) when model doesn't have the groupbycolumn field |
I get the same error. Is there a solution for this issue? |
@sshoj and @TheoJoore what is the compatibility level and mode of your models? The |
@otykier , thnx for you reply. I want to implement this in an Azure Analysis Services model with compatability level 1500. If I set it local to for example 1510 the error in Tabular Editor is gone, but then when I deploy it to the Azure Analysis Server I get this message |
As I said above, this only works for Power BI models - not SSAS / AzureAS models. Microsoft documentation for GroupByColumns:
|
So to be clear: there is no option to add a field parameter to an AzureAS model? |
Correct. You can, however, use the DirectQuery over AS feature in Power BI, to build a Power BI model based on an AzureAS database, to which you can then add a field parameter: https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters#limitations
|
This code generated a correct looking calculated table that wouldnt compile for its life. In the end the markup was the problem. After removing any spaces or tabs generated by the code and making the markup myself the calculated table worked instantly. Would still like this as a feature in TE3! |
@otykier - this would be great if in TE2 you could select columns from multiple tables when holding CTRL, I can select many columns from one table, or many tables, but not columns from different tables. What am I missing?? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
This is a new May 2022 desktop feature, and it apparently goes beyond the DAX with a number properties that need to be set in order for Tabular to recognize it.
A full thread of the details can be found at https://twitter.com/markbdi/status/1526602566486081536?s=20&t=1Z2Ny-GTJlSeKocTxneX3g
Would be nice if we could right-click on Table in the TOM, and create a new Field Parameter table, with a bit of assist on the DAX (one or two rows of example code would be sufficient I think, no need initially for a full UI like PBID has) with all underlying properties set correctly.
The text was updated successfully, but these errors were encountered: