Tabulator works great for column-oriented tables; that is tables that have a fixed number of columns and an increasing number of rows.
However, in the accounting world, tables are horizontal with a fixed number of rows and an increasing number of columns. When building an accounting-style table, time is expressed horizontally. See example:
Is it possible for Tabulator to support accounting-style/horizontal tables? Perhaps it already does but I just don't know how to configure that.
You would just have to structure your data in a format that tabulator could understand.
So for each cost item you would create a row data object that would contain the data for that cost item, and then create a column for each of the quarterly results. we could use column groups to gain headers similar to your example
So your column definitions would look a bit like this:
var columns = [
{title:"Cost Item", field:"cost_item"},
{title:"Description", field:"desc"},
{title:"Budget", field:"budget", bottomCalc:"sum"},
//define your quarters
{title:"MAR18 - MAY18, columns:[
{title:"Q1", columns:[
{title:"HISTORIC", field:"q1", bottomCalc:"sum"},
]}
]},
{title:"JUN18 - AUG18, columns:[
{title:"Q2", columns:[
{title:"HISTORIC", field:"q2", bottomCalc:"sum"},
]}
]}
];
And your rows would look a bit like this:
var rows = [
{cost_item:"A1", desc:"Directly incurred: Staff", budget:1000000, q1:20000, q2:20000},
{cost_item:"A2", desc:"Directly incurred: Travel", budget:150000, q1:6000, q2:6000},
]
You can then set them on your table with:
var table = new Tabulator("#example-table",{
data:rows,
columns:columns,
});
Related
Below is my example code:
db = QSqlDatabase.addDatabase('QSQLITE')
db.setDatabaseName('book.db')
db.open()
model = QSqlQueryModel()
model.setQuery("SELECT * FROM card")
self.tableView.setModel(model)
I am using QSqlQueryModel, Qtablevie, Sqlite3, and able to view all rows in my table. But i want to view only last two rows of my table which are newly inserted rows in to the table. The table has no "id" field and it has numaric and text fields. How is it possible?
Below is the table image:
If you want to get the last 2 elements ordered by any field that indicates the insertion order, in your case "rowid", then you have to use a filter in the SQL command like this:
model.setQuery("SELECT * FROM card ORDER BY rowid DESC LIMIT 2")
Another possible option is to filter the table using QSortFilterProxyModel but it is more inefficient.
Is it possible to update column position with Tabulator?
Or is there a way to do it?
Apparently there is no function to do it.
A moveColumn function will be coming in the 4.2 release next week.
In the mean time you can easily change the order of columns in the table by calling the deleteColumn function and then the addColumn function.
//remove column
table.deleteColumn("age");
//add column elsewhere in the table after the name column
table.addColumn({title:"Age", field:"age"}, "name");
or by changing the column definition array and resubmitting it using the setColumns function
//define new column layout
var columns = [
{title:"Name", field:"name"},
{title:"Age", field:"age"},
{title:"Gender", field:"gender"},
]
//replace all columns
table.setColumns(columns);
Full documentation on these features can be found in the Columns Documentation
I have a table in SSAS tabular mode that shows how individual pieces of products moved through different sections of a production line:
Product_ID, section_ID, Category_id (product category), time_in (when a product entered the section), time_out (when the product exited the section)
This is how the input table looks like:
I would like to write a measure in DAX that can show me the stock of each section and product category day-by-day as shown below by counting the number of distinct product ids which were in a particular section on that day.
I'm using SQL Server 2017 Analysis Services in Tabular Mode and Excel Pivot Table for representation.
Create a new table that has all of the dates that you want to use for your columns. Here's one possibility:
Dates = CALENDAR(MIN(ProductInOut[time_in]), MAX(ProductInOut[time_out]))
Now create a measure that counts rows in your input table satisfying a condition.
ProductCount =
VAR DateColumn = MAX(Dates[Date])
RETURN COUNTROWS(FILTER(ProductInOut,
ProductInOut[time_in] <= DateColumn &&
ProductInOut[time_out] >= DateColumn)) + 0
Now you should be able to set up a pivot table with Category_id on the rows and Dates[Date] on the columns and ProductCount as the values.
Using Power Pivot in Excel 2016
I have one dim table called "Roster" with 218 unique 'Employee Names' and other attributes for the employees
I have three fact tables called "Forecast," "Actual," and "Invoice," each with the related 'Employee Name' columns, in addition to many other attributes and values. I want a distinct count of 'Employee Name' across all three of those tables, depending on what I'd like to pivot them by in my pivot table, like 'Project' or 'Company.' I've read about counting across multiple columns from one table, but I'm trying to count across multiple tables.
When I create measure of:
Headcount:=calculate(DISTINCTCOUNT('Roster_Table'[Employee Name]),'Actual','Forecast','Invoice'), and throw it in my pivot table, I get a very small count of 14, which is probably the ones that are unique to only one of the three tables.
When I create measure of: Headcount:=DISTINCTCOUNT('Roster_Table'[Employee Name]), I get all 218
The true number should be around 170. Any ideas of how to make this work?
Thanks
Please try the following DAX calculation:
COUNTROWS(
DISTINCT(
UNION(
VALUES('Forecast'[Employee Name]),
VALUES('Actual'[Employee Name]),
VALUES('Invoice'[Employee Name])
)
)
)
I want to filter one table by using a column in another table. Here is my table to be filtered:
Table 1
deviceid, user_number
001,400
002,500
003,600
004,700
009,1000
I have another table:
Table 2
deviceid
001
003
004
Now I can filter table 1 with table 2 by writing something like this:
"Filtered Rowxx" = Table.SelectRows(#"Column1", each ([deviceid] <> "001"
and [deviceid] <> "003" and [deviceid] <> "004")
Since Table 2 changes all the time, how can I define a query under power query to achieve this please?
It sounds like you want an anti-join.
Table.Join with JoinKind.LeftAnti will filter out rows from the left table that match the right table.
let
Column1= #table({"deviceid", "user_number"}, { {"001", "400"}, {"002", "500"}, {"003", "600"}, {"004", "700"}, {"009", "1000"} }),
Table2 = #table({"__deviceid"}, { {"001"}, {"003"}, {"004"} }),
AntiJoin = Table.Join(#"Column1", "deviceid", Table2, "__deviceid", JoinKind.LeftAnti),
SelectColumns = Table.SelectColumns(AntiJoin, {"user_number", "deviceid"})
in
SelectColumns
One benefit of Table.Join is it's likely to fold your filter to a backing relational database server, while list operations tend not to fold. (But if your query runs quickly, it doesn't really matter.)
One problem with Table.Join is it can't handle multiple columns with the same name, so I had to rename the Table2's "deviceid" column.
You can get the column deviceid of Table2 by using Table2[deviceid], which gives you a list. We can check if the current deviceid is in the list with List.Contains, so your filter can look something like this:
"Filtered Rowxx" = Table.SelectRows(#"Column1", each not List.Contains(Table2[deviceid], [deviceid]))