Shopify api total sales - shopify

how can i get total sales from shopify store for api call? anyone have idea?I got total price by date but not total sale.
I need total sales by min and max date.
Thanks in advance.

You can get the total amount of orders that you need for the range that you need, then get the ceiling of the order count divided by the amount per page (this will get you the total amount of pages you need to get). For example, if you have 730 orders for a day and 250 orders per page, you will need to get 3 pages of orders. You can then get the 3 pages of orders and add up the totals.
https://docs.shopify.com/api/reference/order#count

you have to loop the order list response and sum up the "total_price" field. If you need accuracy you have to subtract any refunds sum from your total sum.

Yes there is a json object for refunds. In Python you can retrieve the refund information with json_response['orders'][number_in_the_list]['refunds']. Make sur to add to your GET request the status=any endpoint so you'll get /admin/api/2021-07/orders.json?status=any plus your other endpoints.

Related

AWS QuickSight: maxOver() calculated field?

I am a stock trader who visualizes data in QuickSight. I identify the trades I want to submit to the market, sometimes for the same stock, at the same time, but in opposite directions depending on the price of the stock at that time. See below for an example of trades I might identify for 1/19/22 0800:
Date
Hour
Stock
Direction
Price
Volume
1/19/22
0800
Apple
BUY
$10
2
1/19/22
0800
Apple
SELL
$20
1
1/19/22
0800
Microsoft
BUY
$15
3
Using QuickSight, I want to visualize (in pivot tables and charts) the volume that I trade, using the maximum possible trade volume. For example, QuickSight simply sums the Volume column to 6, when really I want it to sum to 5, because the max possible trade volume for that hour is 5 (the Apple trades in the example are mutually exclusive, because the stock price cannot be both beneath $10, triggering a BUY, and above $20, triggering a SELL at the same date-time. Therefore, I want the day's traded volume to reflect the MAX possible volume I could have traded (2+3)).
I have used the maxOver() function as so: maxOver({volume}, [{stock}, {date}, {hour}], PRE_AGG), but I would like to view my trade volume rolled up to the day as so:
Date
Volume
1/19
5
Is there a way to do this using QuickSight calculated fields? Should this aggregation be done with a SQL custom field?
Add a new calculated field called
volume_direction_specifier
{Volume} * 10 + ifelse({Direction}='BUY', 1, 2)
This is a single number that will indicate the direction and volume. (this is needed in cases where the max possible volume is the same for both the BUY and SELL entries within the same hour).
Then compute the maxOver on this new field in a calculated field called max_volume_direction_specifier
maxOver({volume_direction_specifier}, [{stock}, {date}, {hour}], PRE_AGG)
Add a new field which will give the Volume for rows that have the max volume_direction_specifier per hour
volume_for_max_trade_volume_per_hour
ifelse(volume_direction_specifier = max_volume_direction_specifier, {volume}, null)
And finally, you should be able to add volume_for_max_trade_volume_per_hour to your table (grouped by day) and its SUM will give the maximum possible trade volume per day.

How can I get calculate buy and sell quantity in pandas?

When I have data of quantity and buy and sell program, I want to get the cumulative quantity by adding a number when it is 'buy' and deducting a number when it is 'sell'. How can I do this in pandas? I know there is .cumsum() function to add it, but I don't know how to deduct it.
You can flip the integer when selling:
df['quantity'].where(df['buy&sell'].eq('buy'), -df['quantity']).cumsum()

How to display the sum of amount with between two given dates with groupwise, in Laravel?

I want to display the customer name and its sum of all the bills he paid between specific dates. I also want the whole list of customers between the 2 given dates with sum of their total bills.
In list what I want is first Customer Name then its regarding sum of all the bill totals.
I have tried many options for it one where I am getting the sum of that bill only every bill is appearing separately while I want to group it by the customer thats all.
Raw query is working in phpMyAdmin but I failed to convert it to Laravel Eloquent. I want to make this raw query to work using Eloquent.
Query:
select customer_id,sum(total),sum(totalcgst),sum(totalsgst),
sum(totaligst) from sales where
date BETWEEN '2018-03-01' and '2018-03-31'
group by customer_id
This is the result I am getting in database
Try this:
ORM_NAME::selectRaw('customer_id, sum(total), sum(totalcgst), sum(totalsgst)')->whereBetween('date', ['2018-03-01', '2018-03-01'])->groupBy('customer_id)->get();

SQL GROUPING SETS averages with multiple many-to-many dimensions

I have a table of data with the following:
User,Platform,Dt,Activity_Flag,Total_Purchases
1,iOS,05/05/2016,1,1
1,Android,05/05/2016,1,2
2,iOS,05/05/2016,1,0
2,Android,05/05/2016,1,2
3,iOS,05/05/2016,1,1
3,Android,06/05/2016,1,3
1,iOS,06/05/2016,1,2
4,Android,06/05/2016,1,2
1,Android,06/05/2016,1,0
3,iOS,07/05/2016,1,2
2,iOS,08/05/2016,1,0
I want to do a GROUPING SETS (Platform,Dt,(Platform,Dt),()) aggregation to be able to find for each combination of Platform and Dt the following:
Total Purchases
Total Unique Users
Average Purchases per User per Day
The first two are simple as these can be achieved via a sum(Total_Purchases) and count(distinct user) respectively.
The problem I have is with the last metric. The result set should look like this but I don't know how to get the last column to be calculated correctly:
Platform,Dt,Total_Purchases,Total_Unique_Users,Average_Purchases_Per_User_Per_Day
Android,05/05/2016,4,2,2.0
iOS,05/05/2016,2,3,0.7
Android,06/05/2016,5,3,1.7
iOS,06/05/2016,2,1,2.0
iOS,07/05/2016,2,1,2.0
iOS,08/05/2016,0,1,0.0
,05/05/2016,6,3,2.0
,06/05/2016,7,3,2.3
,07/05/2016,1,1,1.0
,08/05/2016,1,1,1.0
Android,,9,4,1.8
iOS,,6,3,1.2
,,15,4,1.6
For the first ten rows we see that getting the Average purchase per user per day is a simple division of the first two columns as the dimension in these rows represent a single date only. But when we look at the final 3 rows we see that the division is not the way to achieve the desired result. This is because it needs to take an average for each day in turn to get the overall per day amount.
If this isn't clear please let me know and I'll be happy to explain better. This is my first post on this site!

FIFO Allocation between Sales and Sales Order Table based on Schedule

It's a an Order Processing related query. There is a sales order which will have different products with some specific quantity. Each qty will have schedule for delivery. In this case, for 55 nos it has the schedule as 10, 15, 30. same way it has once more set of schedule. In Sales details table you get detail of the material sold against each item. You will get details like sale order no and item line no. We need to take schedule qty in FIFO basis and allocate the required qty. I need to get a result set as shown and have to update the sales order detail table. Please help me Screenshot
Resolved Myself. Need to make use of Loops and allocate the quantities to the Delivery schedules.