I need to filter commission depend on amount means I give a amount like 300000 and get the commission for those slab where 300000 is match
SlabStartAmount
SlabEndAmount
CommissionAmount
100000
200000
62.5
2000001
5000000
75
5000001
7500000
81.25
7500001
10000000
87.5
10000001
0
100
You can use a condition to find out the slab
WHERE #Amount BETWEEN SlabStartAmount AND SlabEndAmount
See this fiddle.
Related
I have series of data like below
PRICE AMOUNT TOTAL BUYER SELLER
2.43 250 607,5 TRADER_B TRADER_B(*)
2.43 500 1215 TRADER_D TRADER_B(*)
2.43 13000 31590 TRADER_D TRADER_B(*)
2.43 17000 41310 TRADER_C TRADER_B(*)
2.43 15000 36450 TRADER_A TRADER_B(*)
2.43 10000 24300 TRADER_E TRADER_B(*)
2.43 20000 48600 TRADER_F TRADER_B(*)
2.42 100 242 TRADER_A(*) TRADER_C
2.42 1500 3630 TRADER_A(*) TRADER_F
2.42 10000 24200 TRADER_A(*) TRADER_F
2.42 14500 35090 TRADER_A(*) TRADER_C
2.42 11000 26620 TRADER_A(*) TRADER_A
2.41 400 964 TRADER_A(*) TRADER_B
2.41 200 482 TRADER_B TRADER_C
2.41 1200 2892 TRADER_C TRADER_A
2.40 1000 2400 TRADER_B TRADER_D
2.40 15000 36000 TRADER_F TRADER_E(*)
2.40 20000 48000 TRADER_F TRADER_E(*)
2.40 7500 18000 TRADER_B TRADER_E(*)
2.40 8000 19200 TRADER_A TRADER_E(*)
2.40 2500 6000 TRADER_D TRADER_E(*)
2.40 3500 8400 TRADER_B TRADER_E(*)
My aim, to catching up most stronger buyers and sellers on a stock. That is why I need to grouping by most commonly repeated values according to the BUYER and SELLER columns (I specified the rows by *).
THE BEST BUYERS AMOUNT TOTAL
TRADER_A 37500 90746
THE BEST SELLERS AMOUNT TOTAL
TRADER_E 56500 135600
TRADER_B 75750 184072
If you want the aggregation based on the most common price for each buyer, it would look like:
select bp.*
from (select buyer, price, sum(amount) as amount, sum(total) as total,
row_number() over (partition by buyer order by count(*) desc) as seqnum
from t
group by buyer, price
) bp
where seqnum = 1;
I know there must be some question like me. Seems I cannot find the question, I sorry to ask this question.
Below is my table (SalesTransaction)
ID |SalesID |Amount |AmountReceived |OutStanding |Paid
2041 1000 600000 600000 0 1
2042 1000 1500000 2000000 -500000 1
2043 1000 900000 0 900000 0
2047 1002 300000 0 300000 0
Using SQL Query below:
SELECT ID,
SalesID,
Amount,
AmountReceived,
OutStanding,
Paid,
(CASE
WHEN Paid = 0 THEN (SELECT SUM(OutStanding)
FROM SalesTransaction
WHERE Paid = 1 )
ELSE 0 END) AS BalanceLastSchedule
FROM dbo.SalesTransaction
GROUP BY ID, SalesID, Amount, AmountReceived, OutStanding, Paid
I get result like below:
ID |SalesID |Amount |AmountReceived |OutStanding |Paid |BalanceLastSch
2041 1000 600000 600000 0 1 0.00
2042 1000 1500000 2000000 -500000 1 0.00
2043 1000 900000 0 900000 0 -500000
2047 1002 300000 0 300000 0 -500000
What I want to get like below:
ID |SalesID |Amount |AmountReceived |OutStanding |Paid |BalanceLastSch
2041 1000 600000 600000 0 1 0.00
2042 1000 1500000 2000000 -500000 1 0.00
2043 1000 900000 0 900000 0 -500000
2047 1002 300000 0 300000 0 0.00
Appreciate I get help on this. Thanks.
You are getting the wrong answer because you have not joined the Inner Query to find the sum with the SalesId. try this below script
SELECT
SeqNo,
SalesID,
Amount,
AmountReceived,
OutStanding,
Paid,
ISNULL((CASE
WHEN Paid = 0 THEN (SELECT SUM(OutStanding)
FROM SalesTransaction
WHERE Paid = 1
AND SalesId = T.SalesId)
ELSE 0 END),0.00) AS BalanceLastSchedule
FROM SalesTransaction T;
i just added the below setion inside tour inner query and removed the group By Clause
AND SalesId = T.SalesId
I’m trying to sum the values in a column VAL for the last 14 days from T_DATE, by account.
My expression is
if([RND_FLG]=1 ,Sum([VAL]) over (Intersect([T_ACC],LastPeriods(14,[T_DATE]))),null)
9/10 the results are accurate, but this is not always the case.
Any help is appreciated.
Sample data below:
ALLDATE T_ACC VAL 14DAYVAL
12/13/2016 1501313137 500000 500000
12/15/2016 1501313137 800000 1300000
12/19/2016 1501313137 500000 1800000
12/20/2016 1501313137 500000 2300000
12/21/2016 1501313137 500000 2300000
12/22/2016 1501313137 500000 3300000
12/30/2016 1501313137 200000 3500000
You are probably getting incorrect results when you have gaps in your dates. LastPeriods() isn't the same as n - days so it's aggregating over n number of rows versus days. You can normalize your data to have 1 row per date to get around this.
Try adding a rank column like Rank([T_DATE],[T_ACC]) Then you can sum using over intersect and lastperiods
I need a solution similar to this:
DAX running total (or count) across 2 groups
However slightly more complex.
I have the following:
(apologies for the layout - i can't post pictures)
Name Date Monthly Rev Total Rev Margin( % Rev)
Proj 1 1/08/2014 0 7000 15%
Proj 1 1/09/2014 1000 7000 15%
Proj 1 1/10/2014 1000 7000 15%
Proj 1 1/11/2014 1000 7000 15%
Proj 1 1/12/2014 0 7000 15%
Proj 1 1/01/2015 0 7000 15%
Proj 1 1/02/2015 2000 7000 15%
Proj 1 1/03/2015 2000 7000 15%
Proj 2 1/11/2014 0 16000 10%
Proj 2 1/12/2014 1500 16000 10%
Proj 2 2/12/2014 1500 16000 10%
Proj 2 3/12/2014 1500 16000 10%
Proj 2 4/12/2014 1500 16000 10%
Proj 2 5/12/2014 2000 16000 10%
Proj 2 6/12/2014 2000 16000 10%
Proj 2 7/12/2014 0 16000 10%
Proj 2 8/12/2014 2000 16000 10%
Proj 2 9/12/2014 2000 16000 10%
Proj 2 10/12/2014 2000 16000 10%
Monthly rev is the revenue received in a month, total is the total project value and margin is the percentage of revenue. The table is linked to a dates table by Date.
I need to show margin by date (there are other descriptive columns in the table for slicing) however the margin calc is not straightforward.
In an excel table it would look something like this:
Cumm simple margin | Completion| Cumm complex margin | Margin earnt
0 0% 0 0
150 20% 30 30
300 40% 120 90
450 60% 270 150
450 60% 270 0
450 60% 270 0
750 80% 600 330
1050 100% 1050 450
0 0% 0 0
150 11% 17 17
300 22% 67 50
450 33% 150 83
600 44% 267 117
800 56% 444 178
1000 67% 667 222
1000 67% 667 0
1200 78% 933 267
1400 89% 1244 311
1600 100% 1600 356
Where:
Simple margin is calculated on a cumulative basis as % of monthly Rev
Percentage complete of the project is calculated based on "active" months where revenue is earned
Cumulative simple margin is multiplied by the % complete
Actual margin earned in a particular month is the difference between two months.
Note that Monthly revenue is not necessarily continuous.
No idea how to recreate this in power pivot, any suggestions would be well received.
Cheers
Assuming
That your Project 2 data should run monthly from 1/11/2015 to 1/09/2015 (rather than individual December dates)
You have your data in a table called 'ProjectMargins'
Your DateDim table is called 'Reporting Dates'
Then these are the DAX Measures you need (although there may be simpler methods for achieving these results):
[MonthlyRev]:=SUM(ProjectMargins[Monthly Rev])
[ActiveMonth]:=CALCULATE(COUNTROWS('ProjectMargins'),FILTER('ProjectMargins',[MonthlyRev]>0))
[AllActiveMonths]:=CALCULATE([ActiveMonth],ALL('Reporting Dates'[Date]))
[Completion]:=DIVIDE(CALCULATE([ActiveMonth],FILTER(ALL('Reporting Dates'[Date]),'Reporting Dates'[Date] <= MAX(ProjectMargins[Date]))),[AllActiveMonths])
If you need to calculate TotalRev, from your Monthly Rev, Rather than it appearing in the original source table:
[TotalRev]:=IF(ISBLANK(MAX(ProjectMargins[Margin( % Rev)])),BLANK(),CALCULATE([MonthlyRev],ALL('Reporting Dates'[Date])))
[Rev%]:=MAX(ProjectMargins[Margin( % Rev)])
[Cumm Simple Margin]:=CALCULATE([MonthlyRev]*[Rev%],FILTER(ALL('Reporting Dates'[Date]),'Reporting Dates'[Date] <= MAX(ProjectMargins[Date])))
[Cumm Complex Margin]:=[Completion]*[Cumm Simple Margin]
[Previous Month Cumm Complex]:=CALCULATE([Cumm Complex Margin], DATEADD('Reporting Dates'[Date],-1,MONTH))
[Margin Earnt]:=IF([Cumm Complex Margin]>0,[Cumm Complex Margin]-[Previous Month Cumm Complex],BLANK())
NOTE: This assumes that the margin is never negative.
Ensure that the date field from the DateDim table is used in your pivot, not the date field from the Fact table.
I have been searching for a long time how to do this, however due to the words involved when searching it is incredibly hard to find something close to what I am trying to find out!
How can I use the sql CASE expression within a create view?
Could someone please show me the correct syntax?
Below is how mine looks at the moment, but it is not working correctly.
create view vw_price as
select vehicle.price
(case when price between 0 and 999 then ‘0-999’
when price between 1000 and 1999 then ‘1000-1999’
when price between 2000 and 2999 then ‘2000-2999’
when price between 3000 and 3999 then ‘3000-3999’
when price between 4000 and 4999 then ‘4000-4999’
when price between 5000 and 5999 then ‘5000-5999’
when price between 6000 and 6999 then ‘6000-6999’
when price between 7000 and 7999 then ‘7000-7999’
when price between 8000 and 8999 then ‘8000-8999’
when price between 9000 and 9999 then ‘9000-9999’
end) as price_group from vehicle;
The below syntax should work to create the required view. I think you are just missing a comma before the case statement.
USE [<<<database_name>>>]
GO
CREATE VIEW vw_price
AS
select price,
(case
when price between 0 and 999 then '0-999'
when price between 1000 and 1999 then '1000-1999'
when price between 2000 and 2999 then '2000-2999'
when price between 3000 and 3999 then '3000-3999'
when price between 4000 and 4999 then '4000-4999'
when price between 5000 and 5999 then '5000-5999'
when price between 6000 and 6999 then '6000-6999'
when price between 7000 and 7999 then '7000-7999'
when price between 8000 and 8999 then '8000-8999'
when price between 9000 and 9999 then '9000-9999'
end) "price_group" from vehicle;
GO