2016-06-23 21:25:47 +03:00
|
|
|
# powerbi-models
|
2016-08-06 02:42:26 +03:00
|
|
|
[![Build Status](https://img.shields.io/travis/Microsoft/powerbi-models.svg)](https://travis-ci.org/Microsoft/powerbi-models)
|
|
|
|
[![NPM Version](https://img.shields.io/npm/v/powerbi-models.svg)](https://www.npmjs.com/package/powerbi-models)
|
|
|
|
[![NPM Total Downloads](https://img.shields.io/npm/dt/powerbi-models.svg)](https://www.npmjs.com/package/powerbi-models)
|
|
|
|
[![NPM Monthly Downloads](https://img.shields.io/npm/dm/powerbi-models.svg)](https://www.npmjs.com/package/powerbi-models)
|
2016-07-23 01:59:57 +03:00
|
|
|
[![GitHub tag](https://img.shields.io/github/tag/microsoft/powerbi-models.svg)](https://github.com/Microsoft/powerbi-models/tags)
|
2016-06-23 03:06:18 +03:00
|
|
|
|
2016-06-23 21:40:09 +03:00
|
|
|
Contains JavaScript & TypeScript object models for Microsoft Power BI JavaScript SDK.
|
|
|
|
|
2016-06-28 02:29:58 +03:00
|
|
|
For each model there is a TypeScript interface, a json schema definitions, and a validation function to ensure a given object is a valid model.
|
2016-06-23 03:06:18 +03:00
|
|
|
|
2016-08-06 02:42:26 +03:00
|
|
|
## Documentation
|
|
|
|
### [https://microsoft.github.io/powerbi-models](https://microsoft.github.io/powerbi-models)
|
|
|
|
|
2016-06-23 03:06:18 +03:00
|
|
|
## Getting Started
|
|
|
|
|
|
|
|
Install
|
2016-07-13 20:19:05 +03:00
|
|
|
|
|
|
|
```bash
|
2016-06-23 03:06:18 +03:00
|
|
|
npm install --save powerbi-models
|
|
|
|
```
|
|
|
|
|
|
|
|
Import
|
2016-07-13 20:19:05 +03:00
|
|
|
|
|
|
|
```typescript
|
2016-06-23 03:06:18 +03:00
|
|
|
import * as models from 'powerbi-models';
|
|
|
|
```
|
|
|
|
|
|
|
|
Usage
|
2016-07-13 20:19:05 +03:00
|
|
|
|
2016-08-19 01:20:06 +03:00
|
|
|
Validation:
|
|
|
|
|
2016-07-13 20:19:05 +03:00
|
|
|
```typescript
|
2016-06-23 03:06:18 +03:00
|
|
|
let testObject = { x: 1 };
|
|
|
|
|
|
|
|
const errors = models.validateLoad(testObject);
|
|
|
|
|
|
|
|
if(errors) {
|
2016-06-23 21:40:09 +03:00
|
|
|
console.warn(errors);
|
2016-06-23 03:06:18 +03:00
|
|
|
}
|
|
|
|
|
2016-06-23 21:40:09 +03:00
|
|
|
```
|
|
|
|
Would output to the console:
|
2016-07-13 20:19:05 +03:00
|
|
|
|
|
|
|
```typescript
|
2016-06-23 21:40:09 +03:00
|
|
|
[
|
|
|
|
{
|
|
|
|
message: 'accessToken is required'
|
|
|
|
}
|
|
|
|
]
|
2016-06-30 17:59:26 +03:00
|
|
|
```
|
2016-08-19 01:20:06 +03:00
|
|
|
|
|
|
|
Creating filters:
|
|
|
|
```typescript
|
|
|
|
const basicFilter: models.IBasicFilter = {
|
|
|
|
target: {
|
|
|
|
table: "Products",
|
|
|
|
column: "Version"
|
|
|
|
},
|
|
|
|
operator: "In",
|
|
|
|
values: [
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
const advancedFilter: models.IAdvancedFilter = {
|
|
|
|
target: {
|
|
|
|
table: "Products",
|
|
|
|
column: "Name"
|
|
|
|
},
|
|
|
|
logicalOperator: "Or",
|
|
|
|
conditions: [
|
|
|
|
{
|
|
|
|
operator: "Contains",
|
|
|
|
value: "Power"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
operator: "Contains",
|
|
|
|
value: "Microsoft"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
Or use the constructor methods:
|
|
|
|
```typescript
|
|
|
|
const advancedFilter = new models.AdvancedFilter(
|
|
|
|
{
|
|
|
|
table: "Products",
|
|
|
|
column: "Name"
|
|
|
|
},
|
|
|
|
"Or",
|
|
|
|
{
|
|
|
|
operator: "Contains",
|
|
|
|
value: "Power"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
operator: "Contains",
|
|
|
|
value: "Microsoft"
|
|
|
|
}
|
|
|
|
);
|
2016-09-08 03:27:49 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Date Formatting
|
|
|
|
Dates should be formated using [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) standard. Example: `2016-09-08T00:15:46.861Z`
|
|
|
|
|
|
|
|
This is how dates are naturally serialized to JSON:
|
|
|
|
```
|
|
|
|
new Date().toJSON(); //=> 2016-09-08T00:15:46.861Z
|
|
|
|
```
|
|
|
|
|
|
|
|
An example filter using this Date format would look like the following:
|
|
|
|
|
|
|
|
```
|
|
|
|
{
|
|
|
|
"$schema": "http://powerbi.com/product/schema#advanced",
|
|
|
|
"target": {
|
|
|
|
"table": "Time",
|
|
|
|
"column": "Date"
|
|
|
|
},
|
|
|
|
"logicalOperator": "And",
|
|
|
|
"conditions": [
|
|
|
|
{
|
|
|
|
"operator": "GreaterThan",
|
|
|
|
"value": "2014-06-01T07:00:00.000Z"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2016-08-19 01:20:06 +03:00
|
|
|
```
|