How to calculate the total revenue of a day using vb.net? - windows

Currently I'm developing a vb.net program which is based on 'Movie Ticket Purchasing System'. Right now I'm trying to develop a code where, once the cinema is closed for the day, the system will calculate the total amount of collections in both movie ticket purchases and snack/drink purchases.
Let's say that:
TicketPrice - total price of movie tickets purchased
SnackPrice - total price of snacks/drinks purchased
TotalCinemaPrice - TicketPrice + SnackPrice
So, "TotalDayRevenue", for example, will be the total number of tickets, snacks and drinks sold throughout the day.
Also, I know that 'For Loop' will be used in order to get this kind of value, but I don't know how to efficiently, and properly write the code.
Help is much appreciated, thank you.

First create a variable to store the total day revenue:
double totalAmount = 0;
Then get the amount of tickets and snacks you've sold and multiply that with the price. Then add it to the total day revenue:
totalAmount += amountOfTicketsSold * priceForOneTicket;
totalAmount += amountOfSnacksSold * priceForOneSnack;
Kind regards

Related

DAX Power Pivot measure – last previous value with where condition

I am looking for a DAX measure to calculate volume = quantity * price, where the price is the last previous price for a given product.
In other words, I am looking for a DAX measure with last previous value with a "where" condition.
Take this example from the attached workbook:
I have 3 products:
Apples
Bananas
Oranges
Each of these has a USD price and volume is simply quantity * price.
However, oranges can also be exchanged for apples!
To sum up the value of these orange-for-apple exchange transactions with the other USD transactions, I first need to calculate the USD value of the oranges, and for this I need to know the last price paid for an apple, i.e. last previous price, where product = apple.
Take this example from the attached workbook:
The last previous price paid for an apple was USD 5
The total USD price (volume) for 10 apples sold is: 10*50= USD50
Subsequently 3 oranges were exchanged for apples, at a rate of 4 apples per orange
The total USD price (volume) for 3 oranges is: 3x4x5= USD60, i.e. # number of oranges * ratio oranges to apples * last previous price for an apple
Total transaction volume = 50 + 60 = USD 110
There are a few more examples in this sample file:
https://docs.google.com/spreadsheets/d/1PTaKg9a3Yv1um2RTnpeYC4gdLVjQXEzl/edit?usp=sharing&ouid=106440602605717108817&rtpof=true&sd=true
What I am looking for is a DAX formula that gives me the last previous value with a condition or filter or where clause.
The following works as a calculated column, but is expensive, because it uses EARLIER:
=
VAR Conditional_Volume = IF(Transactions[product] = "orange_apple",
CALCULATE(
MAX(Transactions[price]),
ALL(Transactions),
(Transactions[product]="apple"),
Transactions[transaction_id] < EARLIER(Transactions[transaction_id])
)*Transactions[price]*Transactions[quantity],Transactions[price]*Transactions[quantity])
RETURN Conditional_Volume

Calculate percentage when an item can be assigned to multiple categories

this might be a stupid question but I'm blanking at the moment and can't find the answer in google.
I have the following example table
customer
bought
A
food
B
food,drink
C
drink
D
drink
now how do I calculate the percentage of customers that bought food/drink over total customers? what would be the best way to calculate this?
solution
% food = #customers who bought food / #total unique customers = 2 / 4 = 50%
% drink = #customers who bought drink / #total unique customers = 3 / 4 = 75%
the problem here is the total % exceeds 100%
solution - count customer B twice, once for drink and once for food
% food = #customers who bought food / #total customers = 2 / 5 = 40%
% drink = #customers who bought drink / #total customers = 3 / 5 = 60%
the total is 100% but is this the correct way to calc % in this case?
The issue is obviously that one customer can buy both food and drink and I'm not sure how to handle this case. Any help would be appreciated. Thank you!
UPDATE:
thanks for the answer. It makes sense to remove altogether the customers who bought both products. But now I'm wondering what happens if there are more than 2 categories?
Example as follows, now we have an additional product (ice cream) in the mix
customer
bought
A
food
B
food,drink
C
drink
D
drink
E
drink,ice cream
F
ice cream
G
food,drink,ice cream
I guess with the same logic we can remove customer G since they bought all the products? And how should we handle customer E and B?
I think that what you are looking for is simply to eliminate the number of customers that purchased both products.
If you are looking for unique combinations of customers who purchased only a specific product then:
3 unique customers bought a single unique item
1/3 food => 33%
2/3 drink => 66%
The ones who bought both products, don't matter in these calculations since they add the same percentage to both cases.
EDIT:
I used excel to help me out. I hope that is fine
I added your data into an excel sheet and created a crosstable pivot.
I've set the Customers as columns and the Products as rows, in order to see what each individual customer has purchased via the values field Count of Product
I've changed the count of Product into the formula for % of Total
in order to show me for each product, the percentage split between the customers, so for example if customer B bought both drink and food he will be shown as 50% in both corresponding rows. If he bought all 3 then 33%
The grand total column, will contains the final percentage for each product row item. Excel calculates it the same way as states in some comments, it counts the products total instead of the customers total, which makes sense since that is your data set being consumed, and not the customers themselves.
If we swap the rows and columns around and do the same calculations, we see individual percentages for each customer (how much % of product they each individually purchased) and we can sum them up for each product. The result is the same

Exchange rates for ENDOFMONTH

I have an Exchange Rate table that I'm trying to get the ending months calculation
It's using a minimum of 3 currencies lets use GBP USD EUR
I need to return when selecting that currency the End of month Currency
So something like k
EOMCcy=:IF(HASONEVALUE('Ccy'[Currency Symbol]),
CALCULATE([Exchange Rate],ENDOFMONTH('Exchange Rates'[Date]) ,BLANK()))
I know I need to validate the currency somewhere and I'm trying many thinks as I have a fromCcy and toCccy column e.g GBP USD
This would show in the [Exchange Rate] column =1.22
I was hoping someone can point me in the right direction or offer a better method with my code
Thank all
So I think I solved it
EOMCcy:=IF(HASONEVALUE('Ccy'[Currency Symbol]),
CALCULATE (
SUM ([ExchangeRate]),
FILTER (
ALL ( 'Exchange Rates'[Date]),
'Exchange Rates'[Date] = ENDOFMONTH('Exchange Rates'[Date])
)
),BLANK())

Complicated Cube Query

I'm working on a fairly complicated view, which calculates the total cost of a guest's stayed based on data pulled from four different tables. The output however is not exactly what I want. My code is
CREATE OR REPLACE VIEW Price AS
SELECT UNIQUE
Booking.Booking_ID AS "Booking",
Booking.GuestID AS "Guest ID",
Room.Room_Price*(Booking.CheckOutDate-Booking.CheckInDate) AS "Room Price",
Add_Ons.Price AS "Add ons Price",
Room.Room_Price*(Booking.CheckOutDate-Booking.CheckInDate) + (Add_Ons.Price) AS "Total Price"
FROM Booking JOIN Room ON Room.Room_Num = Booking.Room_Num
JOIN Booking_Add_Ons ON Booking.Booking_ID = Booking_Add_Ons.Booking_ID
JOIN Add_ons ON Booking_Add_Ons.Add_On_ID = Add_Ons.Add_On_ID
ORDER BY Booking.Booking_ID;
Now, I'm trying to get this to return the total cost of all Addons, plus the cost of the hotel rooms as the total price, however it is returning the cost of the rooms + each of the addons on separate lines. As follows:
My question is, is it possible to use something like CUBE, or SUM to add up the rows, so that there is only one entry for each of the Bookings with the total price of all add-ons accounted for?

How to recalculate tax on new row total in magento?

I’m making a call to $item->calcRowTotal() on a Mage_Sales_Model_Quote_Item object.
This works great to reset the row total and base row total, but it does not affect the row total including tax (row_total_incl_tax) attribute on the item.
I assume I have to manually do this after I have the new row total but I can’t figure out how to properly calculate the tax and populate the row_total_incl_tax attribute on the item.
Any suggestions would be much appreciated.
Get the tax rate and recalculate row_total_incl_tax. Here's how you can get tax rate.
Assuming your order no. is 101.
$sale = Mage::getModel('sales/sale)->load(101)
$taxModel = Mage::getModel('sales/order_tax')
->load($sale->getId(), 'order_id');
$taxRate = $taxModel->getPercent()
I think you know how to calculate the tax amount based on row total value.
Edit:
Get tax based on product:
$product = Mage::getModel('catalog/product')->load($item-getProductId());
$request = Mage::getSingleton('tax/calculation')
->getRateRequest()
->setProductClassId($product->getTaxClassId());
$taxRate = Mage::getSingleton('tax/calculation')
->getRate($request);
So you know the tax rate, row_total_incl_tax is sum of tax * qty + total amount (or you can calculate anyway you want). May be you need to check if item price is included tax or not, you can do this by Mage::getModel('Tax/Config')->priceIncludesTax()

Resources