There is a well-known problem connected with creating custom visuals for Power BI Report Sever
- you can't create multiple unrelated dataViewMappings
. It means that every field you put inside Fields
must be related.
There have been a long-lasting request from users to add this feature.
However, it looks like Microsoft
hasn't implemented it yet.
https://github.com/Microsoft/PowerBI-visuals/issues/251
I found a workaround - you can combine all your different tables in one and chain with a tableName
key.
For example, you have a table A
:
value1|value2|tableName
1|2|tableA
3|4|tableA
and a table B
:
value3|tableName
a|tableB
b|tableB
You create a tableC
by using M
function Table.Combine({tableA, tableB})
or other technique. As a result, it looks like this:
value1|value2|value3|tableName
1|2|null|tableA
3|4|null|tableA
null|null|a|tableB
null|null|b|tableB
Then, inside your custom visual you implement the following function which parses the input:
public parseOptionsToTables(options: VisualUpdateOptions) {
var i: number;
var j: number;
var cntRows: number;
var cntCols: number;
var nameTable: string;
var tempDict: {} = {};
var tempVal: any;
var colName: string;
var cats: any = options.dataViews[0].table;
this.tables = {};
cntCols = cats.columns.length;
cntRows = cats.rows.length;
for (i = 0; i < cntRows; i++) {
tempVal = null;
colName = null;
nameTable = null;
tempDict = {};
for (j = 0; j < cntCols; j++) {
//for every row - check the TableName column and add to dict
tempVal = cats.rows[i][j];
colName = cats.columns[j].displayName;
if (colName == 'tableName') {
nameTable = tempVal;
} else {
//add id not null
if (tempVal !== null) {
tempDict[colName] = tempVal;
}
}
}
//push to dict
this.tables[nameTable] = this.tables[nameTable] || [];
this.tables[nameTable].push(this.deepcopy(tempDict));
}
}
As a result, it creates a this.tables
object with your tableA
and tableB
inside.
Although it helps to solve the main problem, I can't get out of feeling of creating crutches. So, are there any other approaches to solve this problem more effeciently?