multiplication two columns in data grid wpf - wpf

I have a three columns
productname - mount - price
I need to show a fourth column when I insert mount and price , the fourth column is mount multiplication price as an example
productname - mount - price - Total,
Total= mount* Price

In your model class add another property called as Total and where you assign the other property's there assign the total value, now you can bind the Total property in your total column of data grid.
ex:
productname = aaa
mount = 1
price = 10
Total= mount * Price

Related

SQL - Remove Duplicates

I've inherited data from another provider and have 2 tables to clean up
Rooms
Items
Items are within a Room and are linked via Rooms.RoomID / Items.RoomID
Each time an Item has been inspected it has created a Duplicate of the Room & Item, so I have 6 records for each Room and each Item (Each with a unique RoomID, so 1 to 1)
My aim is to remove the Duplicate Rooms and keep only the latest set of records, then update the Items table with the RoomID (So I have 1 to Many i.e. 1 Room with 6 Item records)
I can GROUP the Rooms and obtain the MAX RoomID but don't know how to do the UPDATE
A kind of suedo would be this:
UPDATE a
SET a.RoomID = MAX(b.RoomID)
FROM [dbo].[tmp_Items] a
inner join [dbo].[tmp_Rooms] b on b.PropertyID = a.PropertyID
and b.FloorLevel = a.FloorLevel
and b.Reference = a.Reference
The combination of PropertyID, FloorLevel, and Reference provides a unique link between Items and Rooms as these columns are in both tables and Reference is unique to each floor of a property (Each Room of each Floor is numbered starting from 1)
Any help or guidance appreciated :)
Use a subquery to aggregate before joining:
UPDATE i
SET i.RoomID = r.max_roomid
FROM [dbo].[tmp_Items] i JOIN
(SELECT PropertyID, FloorLevel, Reference, MAX(r.RoomID) as max_roomid
FROM [dbo].[tmp_Rooms] r
GROUP BY PropertyID, FloorLevel, Reference
) r
ON r.PropertyID = i.PropertyID AND
r.FloorLevel = i.FloorLevel AND
r.Reference = i.Reference;

Descendants to selected only

The Product Hierarchy consists of 3 levels:
Category,
SubCategory
and Product
I have firstly created a dynamic set [Selected Products]:
CREATE DYNAMIC SET [Selected Products] as (
EXISTING [Product].[Product].members - [Product].[Product].[All]
);
I have a measure_ that is calculated as follows:
CREATE MEMBER CURRENTCUBE.[MEASURES].[MyMeasure(%)_]
AS IIF([Measures].[Total] <> 0, [Measures].[SomeMeasure]/[Measures].[Total], NULL)
and it is used to calculate the following measure:
CREATE MEMBER CURRENTCUBE.[MEASURES].[MyMeasure(%)]
AS
(
IIF(
[Product].[Product Hierarchy].CurrentMember IS [Product].[Product Hierarchy].[All]
,AVG([Selected Products],[MEASURES].[MyMeasure(%)_]),
AVG(Descendants([Product].[Product Hierarchy].currentmember,[Product].[Product Hierarchy].Levels('Product'),SELF)
, [MEASURES].[MyMeasure(%)_])
)
)
Grand total calclation is fine as it takes all the [Selected Products]
Calculation on Product level is also fine.
The problem is when it comes to calculate on Category or SubCategory level when not all belonging products are selected. The returned values in fact are calculations for all belonging children and not selected only.
Is is possible to amend above Descendants() expression so it refers to [Selected Products] only?
How can I re write?

How to include count and sum query sets for models & views

I am trying to add up the number of tickets (count) and the (sum) of the price of each ticket purchased. The ticket is a fixed price of $25 each. I've used this in my models.py:
class Ticket(models.Model):
venue=models.CharField(max_length=100)
quantity=models.IntegerField(null=True)
price=models.DecimalField(max_digits=10, decimal_places=2)
loop=models.BooleanField(default=True)
purchaser = models.ForeignKey(User, related_name="purchases",
on_delete=models.PROTECT)
created_at=models.DateTimeField(auto_now_add=True)
updated_at=models.DateTimeField(auto_now=True)
I am confused where to do the query sets to get the total number of tickets and the summation of the prices? Would it be
total_price=Ticket.objects.all().aggregate(Sum('price'))
ticket_count = Tickets.objects.count()
Would the above variables (ex: total_price and _ticket_count) be included as columns in the models or it needs to be stated only in the views? Can quantity be the same as count? Thank you very, very much!
More on aggregate
from django.db.models import Sum
# This will give total tickets sold to all the user
total_tickets = Ticket.objects.aggregate(Sum('quantity'))
total_cost = total_tickets * 25

MDX Percentage Row Not Calculating Correctly

I am trying to calculate a percentage row in a table based on a total column derived earlier in the query.
There are two columns then I create a total for that column. In the next row I want a percentage of the total to show. The output should be something like:
Life Non-Life (P&C) SumTotal
Premiums 66,104.44 916,792.51 982,896.95
Percentage 6.73% 93.27% 1
But instead the second line shows zero.
How do I structure the query to calculate correctly?
Here is the mdx code:
with member [LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics].[SumTotal] as SUM([LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics] , [Measures].[Value] )
member [LocationSpecificData].[Data Type].[All].[Percentage] as [LocationSpecificData].[Data Type].[All].[Gross Written Premiums Total - Calculated], [Measures].[Value] ) / ([LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics].[SumTotal], [Measures].[Value] )
Select { [LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics].&[Life], [LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics].&[Non-Life (P&C)], [LocationSpecificClass].[Hierarchy].[All].&[Insurance Market Statistics].[SumTotal] } On Columns ,
{ [LocationSpecificData].[Data Type].[All].[Gross Written Premiums Total - Calculated] , [LocationSpecificData].[Data Type].[All].[Percentage] } On Rows
FROM [CubeDatabase]
Please try the following example, which worked fine in my environment. I've used our date dimension [Datum] with the year attribute [Jahr] to add a second a line by adding [Line2]. The first shown line is the year 2016. Set the calculated measures [M1] and [M2] to your needs and exchange the year dimension accordingly.
WITH
MEMBER [Measures].[M1] AS [Measures].[name of your measure for col 1]
MEMBER [Measures].[M2] AS [Measures].[name of your measure for col 2]
MEMBER [Measures].[Total] AS [Measures].[M1] + [Measures].[M2]
MEMBER [Datum].[Jahr].[Line2] AS
Divide(
([Datum].[Jahr].&[2016], [Measures].CurrentMember),
([Datum].[Jahr].&[2016], [Measures].[Total])
)
SELECT {
[Measures].[M1],
[Measures].[M2],
[Measures].[Total]
} ON 0,
{
[Datum].[Jahr].&[2016],
[Datum].[Jahr].[Line2]
} ON 1
FROM [name of cube]
The result in my environment looks like this:

How to get value from many2one-One2many in (new) product for a calculation in odoo 8?

I've made a custom field in product.template to select a product quality, based on a Many2one relationship with qualities.
qualities_id = field.Many2one(comodel_name="qualities", string="quality")
In the class: qualities there is a One2Many relationship with the class: quality.supplier.
reseller_ids = fields.One2many('supplierinfo', 'product_qual_id', 'Supplier')
Here we can select a quality type e.g. ( id=16 type=B321 ). This quality type (16) can have more then one supplier. So in supplierinfo we have the field product_qual_id (id = 16) that holds multi suppliers (id = 24, 25, 26)
product_qual_id = fields.Many2one('qualities', 'Quality Template')
Supplierinfo holds suppliers and each supplier holds more then one quantity and price. There is a relationship between supplierinfo and supplier prices using the field suppinfo_id.
pricelist_ids = fields.One2many('supplierprice', 'suppinfo_id', 'Supplier Price')
Because of this relationship, supplierprice: suppinfo, holds more then one quantity and corresponding price based on supplierinfo_id. Field that holds these records:
suppinfo_id = fields.Many2one('supplierinfo', 'Supplier information')
Qualities = ( id=16 type=B321 ). This quality type (16) can have more then one supplier. So in supplierinfo we have the field product_qual_id (id = 16) that holds multi suppliers (id = 24, 25, 26) where Record id: 24 in relation to supplierprice has multi qty and prices:
supplierprice id=30 supplierinfo id=24 qty=200, price=285
supplierprice id=31 supplierinfo id=24 qty=300, price=265
supplierprice id=32 supplierinfo id=24 qty=500, price=248
With additional automation, I need the price from supplierprice, based on (less or more) quantity in the main product. (product.template, price). Can anyone push me in the right direction. How can I get the price from supplierprice into a (new) field in my product.template?
I've added an image of the relationship model.
relationship

Resources