Lookup and multiply using fixed tables - datatables

I'm trying to set up a currency conversion using a fixed rate table.
This is an example of the currency rate table...
Currency
Rate
CAD
.80
EUR
1.1
This is an example of the data table...
Currency
Amount
CAD
100000
EUR
100
My formula needs to convert to USD...
Currency Rate * Amount = USD
Ideally the finished table looks like this...
Currency
Amount
USD
CAD
100000
80000
EUR
100
110
What are the proper DAX formula(s) to do this?

You can use calculate measure to perform both Vlookup and calculation at the same time, here is the dax formula:
Forex Conversion = CALCULATE(SUM(Table2[Amount]),Table2[Amount]) *
CALCULATE(SUM(Table1[Rate]),
FILTER(ALL(Table1),Table1[Currency] = EARLIER(Table2[Currency])))
The outcome:

Related

Populate SQL Server table column with percentage

I have created a table that has a column for prices and I have another column called percentage. I want to be able to auto populate the percentage column by dividing a row's price by the total price*100. Is there any way that this is possible?
Example:
Price Percentage
-------------------
8.00 80%
2.00 20%
to get these percentage values:
(price in row 1 / sum of prices) * 100
(price in row 2 / sum of prices) * 100

Calculate Hourly Pay Based on Pay Rate Column

I am trying to calculate the hourly pay based on the pay rate column. Technically, I am trying to see who has hourly pay assigned to that column vs folks that have annual salary in that column.
Employee
Pay_Rate
400001
10283.52
304068
120000
304069
20.25
I am trying to find a decimal and if decimal is found, I seeing if its greater than zero. If its greater than zero, then I leaving it alone assuming its hourly pay; but if decimal isnt found, then I am taking that number and dividing by 2080 to get hourly pay. My logic, however, works well unless there is a decimal in annual pay. How do I code around that?
CASE WHEN ((EMP.PAY_RATE - trunc(EMP.PAY_RATE)) > 0) THEN EMP.PAY_RATE ELSE (EMP.PAY_RATE/2080) END AS "Hourly_Wage",
Sample output from the abve data set is:
Payrate
10283.52
57.692307
20.25
Simply changed the pay rate threshold. I was over thinking this until I read the comment from Thorsten.
CASE WHEN (EMP.PAY_RATE < 600) THEN EMP.PAY_RATE ELSE (EMP.PAY_RATE/2080) END AS "Hourly_Wage"

Convert rate from multiple type of currency to MYR by sql in BigQuery

I want to convert the total rate from multiple type of currency to myr as shown in this table.
I want to use sql in Bigquery to convert the amount from usd to myr.
Please help me for this question.
Thanks
You can use case when expression to convert your currency by multiplying with appropriate conversion rate for MYR.
select (case when currency='USD' then amount*4.15 when currency ='MYR' then amount end) Amount from yourtable

Sum of 2 level discount

I am using SQL Server 2008 R2. I need to calculate sum 2 of levels discount. 1st one is item level, like 10% discount on any item. After offering this discount there is amount to receive is for example Rs.510. But shop keeper will get 500 and give him another discount Rs.10.
Now the second level discount is in main table and item wise discount is in child table. How I can calculate the sum of discount daily or monthly etc. and how I will get the following output. As when I am using inner join the discount in main table will be repeat for N number of items. Sum of discount on item wise is not an issue, but the invoice level is. Please help.
--------------------------------------------------------------
Invoice No. Date Total Discount Invoice Amount
--------------------------------------------------------------
INV-00001 01/01/2020 12 500
INV-00002 01/01/2020 10000
INV-00003 01/01/2020 30 900
--------------------------------------------------------------

Price Calculating formula in SQL

I have been using the following formula in excel but now I a trying with sql:
the formula:
Price field=(ROUND(Cost field/Constant number,1))-0.01
If the cost is 1.43 the price outcome would be according to this formula would be 2.59.
How can I write this formula is sql?
You can use a simple select and round
assuming your column are name Cost field and Constant number
select ROUND(`Cost field`/`Constant number`,2)-0.01 as price
from my_table
or using as Constant number = 30
select ROUND(`Cost field`/30,2)-0.01 as price
from my_table
and as suggestd by Philipp be sure for the proper rounding take a look at https://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html#function_round