Limit number of accepted groupings - powerbi

A custom visual that I am creating for Power BI receives categories and values like this.
dataRoles: [
{
name: 'Category',
kind: VisualDataRoleKind.Grouping,
},
{
name: 'Values',
kind: VisualDataRoleKind.Measure,
}],
Now for the moment I only want to use one category grouping. I found the Tornado chart sample that supports this nicely in the UI. When a second group is dropped it will replace the first instead of being added.
I believe this is achieved by setting conditions in dataViewMappings but I couldn't figure out how. This seems to have no effect:
conditions: [
{ 'Category': { max: 1 }, 'Values': { min: 0 } }
],
Anyone can help?

Take a look at the Aster Plot capabilities. I think they do pretty much what you want. You might just need to set the min on 'Y' to 1 to match your scenario.

Related

Can not use both expression and non-expression parameters in the same request

Basically, I have a table with two indexes that I'm trying to query and filter.
The querying part works for the Table and the index but the problem happens when I try to filter:
ValidationException: Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {QueryFilter} Expression parameters: {KeyConditionExpression}
Here are the params passed to docClient.query():
{
TableName: 'MyTable',
Limit: 15,
ScanIndexForward: false,
IndexName: 'user-date-index',
KeyConditionExpression: '#user = :yyyy',
ExpressionAttributeNames: { '#user': 'user' },
ExpressionAttributeValues: { ':yyyy': 'the_user_id' },
QueryFilter: { status: { AttributeValueList: [Array], ComparisonOperator: 'EQ' } }
}
When I call the query with the same params but without the QueryFilter, I get correct results, but I still need to filter (by status in this case, and I have about 5 other options to filter with).
I've spent a few hours trying different things and the AWS docs are not clear enough and no examples are presented, I've spent a whole day to even get to that point.
QueryFilter is considered a Legacy Conditional Parameter. From the previous link:
With the introduction of expression parameters (see Using Expressions in DynamoDB), several older parameters have been deprecated. New applications should not use these legacy parameters, but should use expression parameters instead.
The documentation for QueryFilter recommends using FilterExpression instead.
With FilterExpression, your query may look similar to this:
{
TableName: 'MyTable',
Limit: 15,
ScanIndexForward: false,
IndexName: 'user-date-index',
KeyConditionExpression: '#user = :yyyy',
FilterExpression: '#status = :status',
ExpressionAttributeNames: { '#user': 'user', '#status': 'status' },
ExpressionAttributeValues: { ':yyyy': 'the_user_id', ':status': 'STATUS' }
}

Regex for multiple JSON string

I am trying to work around regex expression for a complicated json string (multiple nested objects).
Here's the json string
{
group: [],
lists: {
customer: {
lists: {
"13067": {
id: "13067",
featured: { enable: false },
},
},
},
},
}
Question is how to get value of 'id'? I tried /\"id\":\"(\d+)"/ but this wont work. Plz help!
rgds.
Are you looking for this?
id\s*:\s*\"(\d+)"
But generally it's better to use some kind of Serialization and Deserialization api(
Jackson) for json structure. As you are mentioning complex json structure some kind of api use are more relevant.

Using breakParent to force a linebreak

I'm working on a prettier plugin and am struggling to understand the breakParent command.
From the command documentation:
Include this anywhere to force all parent groups to break.
The documentation is quite sparse, so maybe I've just completely misunderstood what it's supposed to do, but my expectation would be that it will line break parent groups in exactly the same way they would have if the line exceeded the maximum width.
I would therefore have expected the following commands
{
type: 'group',
contents: {
type: 'concat',
parts: [
'<div>',
{
type: 'indent',
contents: {
type: 'concat',
parts: [{ type: 'line', soft: true }, 'Text', { type: 'break-parent' }],
},
},
{ type: 'line', soft: true },
'</div>',
],
},
}
to print
<div>
Text
</div>
but instead I get
<div>Text</div>
How do I achieve what I thought breakParent would do, i.e. force the surrounding code to line break from inside the group?
And if that's not possible, what does breakParent actually do?
(Obviously, it can be done by turning the soft lines into hard lines, but that's not the solution I'm looking for because only the code generating "Text" in the example above knows if a line break is needed or not)

Define graphQLSchema properly in Node.js

Doing graphQL first time.I searched for resources but could not found a helpful one.
I have written the following schema, got some help from another stackoverflow post.
schema.js
function getDataFromUrl(){
return [
{
"EventCode": "ET00029280",
"EventType": "CT",
"EventTitle": "OYSTERS Beach Park",
"VenueName": "Newexcelsior",
"VenueRegion": "Mumbai"
},
{
"EventCode": "ET00030629",
"EventType": "CT",
"EventTitle": "Stand-Up Comedy: The Trial Room",
"VenueName": "Newexcelsior",
"VenueRegion": "Mumbai"
}
];
}
const eventType = new GraphQLObjectType({
name: 'Event',
fields: {
EventTitle: {
type: GraphQLString,
description: 'Event Title'
},
},
});
const eventListType = new GraphQLObjectType({
name: 'EventList',
fields: {
events: {
type: new GraphQLList(eventType),
description: 'List of items',
},
},
});
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
eventList: {
type: new GraphQLList(eventListType),
resolve: () => getDataFromUrl(),
}
}
})
});
module.exports = schema;
When I query
{
eventList {
events {
EventTitle
}
}
}
I get this response:
{
"data": {
"eventList": [
{
"events": null
},
{
"events": null
}
]
}
}
I am expecting some changes in my schema, however my desired response is
{
"data": [
{
"EventTitle": "OYSTERS Beach Park"
},
{
"EventTitle": "Stand-Up Comedy: The Trial Room"
}
]
}
Please also suggest some links where I learn basics.
It looks like what's tripping you up the most right now is how you're defining a list. There's no need to define a separate type called EventList -- when you specify GraphQLList(someOtherType) you are already telling GraphQL to expect an array of that particular type. Your current Schema is expecting an array of an array of types. Because the structure of the data you're passing in doesn't match your schema, GraphQL can't find a field called EventTitle to match against and so it's returning null.
The fix in this case is to just get rid of eventListType altogether and change the type of your eventList field to eventType instead.
The docs for GraphQL.js are probably going to be your best bet as far as learning the basics. The only problem is the examples they include are way too basic. Here is a list of projects on GitHub that you can checkout to see GraphQL in action.
If you are starting out, I would also highly recommend using Apollo's graphql-tools. Even if you don't use Apollo on the client-side, graphql-tools makes it ridiculously easy to set up the server. Your schema would be much more readable, since you would write it as string rather than an object like you do in vanilla GraphQL.js. And you can easily set up a GraphiQL endpoint in addition to your GraphQL one, which makes debugging much easier :)

Power BI Custom Visual Dataview grouping issue even though not summerized

I am having a problem , that dataView object having the unique values or rows in the table .
i have tried, giving the dataRoles of kind: powerbi.VisualDataRoleKind to Grouping,Measure and GroupingorMeasure. I have even tried out giving the dataViewMappings to categorical(dataReductionAlgorithm: { top: {} }) as well as values(select: [{ bind: { to: 'Y' } }]).I have tried by giving Do not summarize option,keep duplicates option, changed the type of the table to whole number ,text,decimal,etc .,but nothing worked for me. what iam missing and what i have to do to bind the entire table as it is in powerbi dev tool.
Below my code,
public static capabilities: VisualCapabilities = {
// This is what will appear in the 'Field Wells' in reports
dataRoles: [
{
displayName: 'Category',
name: 'Category',
kind: powerbi.VisualDataRoleKind.Grouping,
},
{
displayName: 'Y Axis',
name: 'Y',
kind: powerbi.VisualDataRoleKind.Measure,
},
],
// This tells power bi how to map your roles above into the dataview you will receive
dataViewMappings: [{
categorical: {
categories: {
for: { in: 'Category' },
dataReductionAlgorithm: { top: {} }
},
values: {
select: [{ bind: { to: 'Y' } }]
},
}
}],
// Objects light up the formatting pane
objects: {
general: {
displayName: data.createDisplayNameGetter('Visual_General'),
properties: {
formatString: {
type: { formatting: { formatString: true } },
},
},
},
}
};
Thanks in advance.
Power BI pretty much will always summarize in a categorical data view. You can try to work around it by asking for categorical values you think will be unique. but it's subject to your user's judgement.
Switching to a Table data view might be an option, I think you'll see do not summarize take effect there. It has it's own challenges, like identifying which field goes where, and the need to do the math yourself for aggregates.
You might submit an idea at https://ideas.powerbi.com with your desired scenario.
I know this post is old, but it took me forever to find the answer for this same problem. So I did end up using the table format, but it is still a little quirky. Let me give you my example and explain a little:
{
"dataRoles": [
{
"displayName": "Legend",
"name": "legend",
"kind": "GroupingOrMeasure"
},
{
"displayName": "Priority",
"name": "priority",
"kind": "GroupingOrMeasure"
},
{
"displayName": "SubPriority",
"name": "subpriority",
"kind": "GroupingOrMeasure"
}
],
"dataViewMappings": [
{
"table": {
"rows": {
"select": [{
"for": {
"in": "legend"
}
},
{
"for": {
"in": "priority"
}
},
{
"for": {
"in": "subpriority"
}
}
]
}
}
}
]
}
So I want my dataRoles to be GroupingOrMeasures, but I don't believe that is necessary here.
OK, so in the dataViewMappings, I have it marked as "I want my data in a table, in rows constisting of legend values, priority values, and subpriority values."
There are two quirky parts to this. First, your data will be sorted by default in the order in which you declare these things. So if you bring in your legend values first, that is how this table is sorted (by the matching order in which your first columns's values are). And second, it will only save unique rows to the table.
So if I had two rows of:
Legend Priority Subpriority
Canada Recyclables Plastic
Canada Recyclables Plastic
Then there would appear only one value in the table. Also, this means that if you were trying to get all rows of Legend, but only have the legend value selected for the table, you will be getting only one value of each, because repeated values will not make a unique row.
So if you have two rows of:
Canada
Canada
You would get only one row value with the entry of Canada.
And I would also caution you against incomplete data, namely null values. In my above example of Legend Priority Subpriority, if there are repeated values of "blank", only one row will show if all other fields match as well.
The only way to totally guarantee you will get back each individual row, no matter what, is to ensure that each row is unique. In my own work, I was going to just add a unique key column (primary key - indexing the rows - 1, 2, 3, etc.), but I found that priority and subpriority act as a combined unique key. If there are shared priorities, subpriorities are guaranteed to be different.
After knowing this and including these, I can add anything else I want and know that I will get all values back for each individual row.
To see the hierarchy of how to access the data from this point, after you drag in the appropriate values, just use the "Show DataView" tool under or above your visual (it is next to the reload / toggle autoreload icons).
This information was enough for my final solution, so I hope this answer helps others as well.