I have 4 table t1,t2,t3,t4 in a POSTGRESQL database. Each of the table contains 3 common field, "currency" eg INR DOLLAR etc, "debt" eg 12006 , "credit" eg 1000. Credit and debt are integers.
Each table contains multiple entries of every currency possible
I want the sum of debt and credit of each currency across all the 4 tables
currency
debt
credit
INR
12006
1000
DOLLAR
50002
3012
yen
1234
12546
I'm using sequelize, there's no realtion between any 4 tables, I'm only able to add credit and debt of 1 table at a time using this
var a = await asset.findAll({
attributes: ['currency',[sequelize.fn('SUM', sequelize.col('credit')),
'credit'],
[sequelize.fn('SUM', sequelize.col('debt')), 'debt']
],
group: ['currency'],
});
can someone please guide me how can I make a complete outer join using sequelize preferably else raw query would also work
Related
I have a case where customers that use the product generate revenue with it and a small percentage should be paid to my company in return.
I wonder how to model that in stripe. If all customers would make their revenue in the same currency I could setup a usage based price in EUR that reflects the percentage and for each customer generated revenue could create a UsageRecord with an amount that represents the revenue e.g. EUR-Cent like with below code.
However I have customers with multiple currencies and thus their revenue comes in multiple currencies too. And then I cannot use the approach as the UsageRecord just states an amount but not currency. And the amount*pricePerAmount in Currency is specified in the UsagePrice. Thus I would report amounts in a different currency which with this approach would be considered to be in EUR - i.e. that wouldn't work.
const record: Stripe.UsageRecord = await this.stripe.subscriptionItems.createUsageRecord(subscription.stripeUsageSubscriptionItem,
{
quantity: order.customerPrice * 100,
timestamp: Math.trunc(order.createdDate.getTime() / 1000),
action: 'increment',
},
{
idempotencyKey: idempotencyKey
}
);
Also I dont want to create a price item for each currency and apply the UsageRecord to that price since I would need to create lots of such prices(one per currency).
Or should I jsut for each customer order create a paymentintent with the right amount sort of manually?
Weird thing to me is that Stripe itself charges the same way i.e. percent of revenue we make over it - so they somehow can do it right?
Thanks
Tom
So, I was working with GridDB NodeJs Connector, I know the query to find out the null values which shows the records/rows:
SELECT * FROM employees where employee_salary = NaN;
But I want to replace the null values of the column with the mean value of the column, in order to maintain the data consistency for data analysis. How do I do that in GridDB?
The Employee table looks like the following:
employee_id employee_salary first_name department
---------------+---------------+--------------+--------------
0 John Sales
1 60000 Lisa Development
2 45000 Richard Sales
3 50000 Lina Marketing
4 55000 Anderson Development
I have one excel that contains the demand for each part by city:
e.g: the demand for part a for New york is 100 and 1+7=8 for Atlanta
I have another excel containing the inventory level for two warehouses: rural and urban:
e.g: Warehouse "Rural" stocks 50 for part a and warehouse "Urban" stocks zero for part c.
First I joined these two excels with the demand excel being the primary:
I googled about LOD (level of detail) in order to find out the inventory fulfillment for each warehouse by City
-- count the number of unique parts by each city for the demand:
calculated field [a] = { fixed [City]: countd([Part Number demand]) }
-- count the number of parts that are in stock (inventory level>0) by each warehouse:
calculated field [b] = { fixed [City],[Warehouse Location],[Part Number volume]: countd (if [Inventory Level] > 0 then [Part Number demand] end )}
-- calculate the inventory fulfillment %:
calculated field [c] = calculated field [a] / calculated [b]
and I got the following table and I think it is showing the correct fulfillment % by warehouse for each city: e.g: Warehouse "Rural" stocks 33% of unique parts needed by Atlanta.
Question 1: as I include more part numbers into the excel, I only want to consider the top 10 parts by volume needed for each city. I was trying to do the same thing with LOD to first find the total quantity needed per part per city:
{fixed [City], [Part Number demand]: sum([Part Number volume]) }
But it counts the quantity from both excels and I am just wondering if it is possible to only count the quantity from the primary excel (demand not the inventory),
Question 2: once I could count the total quantity needed, how do I transfer it into a filter so that I could only select top 10 parts by demand.
Apologize if these questions are dumb and appreciate for any advice!!
Suppose I have some sample data like so:
and I create a Pivot Table and order by Product > Sales Rep > Sales
If I want the # of sales John had for Product1 I would do =GETPIVOTDATA("Sales",$A$3,"Product","Product1","Sales Rep","John")
But how would I get a count of the entries there are. i.e. for Product1, John had 4 and Kevin had 2
Is it possible to get this count using GETPIVOTDATA()?
To get this you need to add another Sales field to the values section and change the "Summarize By" to Count. Then the formula will =GETPIVOTDATA("Count of Sales",$A$3,"Product","Product1") will get you the count of Product Overall.
i am using the powerBI tools (powerpivot) to create a data model. i am done the model. the model include the product, customer dimensions and sales fact table. i have made the relationship and hierarchy in the model. now i have a requirement to show the total revenue of all the customer who brought product 1,2,3.
for example customer A brought product 1 and product 5 and the total revenue from this customer is 50 so i want to show 50 as a result
customer B bought product 4 and i do not want to include this customer in my output.
i can do the same in microstratergy using relationship filter but how can i do the same in powerpivot or powerview or powerBI.
Please help
Thanks in Advance
In PowerPivot, relate Sales table with Customer table (Lookup table) and Relate Sales table to Product table (Lookup table).
Create following two measures
[HasPurchased X Products] =
OR (
OR (
CONTAINS ( Sales, Sales[ProductID], 1 ),
CONTAINS ( Sales, Sales[ProductID], 3 )
),
CONTAINS ( Sales, Sales[ProductID], 5 )
)
[DesiredMeasure] =
IF (
Sales[HasPurchased X Products] = TRUE (),
SUM ( [Amount] ),
BLANK ()
)
Select Customers in ROWS and add [DesiredMeasure] in VALUES, pivot table will show desired result.
Additionally to what Abhijeet said, which is a nice robust solution, you might also just filter the chart in Power View. Assuming you have a relationship between sales and products table, you can select the chart in Power View, open the Filters pane, select per chart filters, add Product to the chart filters and filter to include only productions 1,2,3. This will automatically calculate the measure. Now Abhijeet's solution is better if you need that calculation to be reused. This solution works great if you're in a 'what if' scenario where you'd like to say "what are the sales for products 1,2,3" and in another breath say "actually i'm interested in sales for products 2,3 only, so me that instead.".
HTH,
-Lukasz
http://dev.powerbi.com
http://blogs.msdn.com/powerbidev