January 31, 2019 at 6:52 pm
i would like to count margin by category.
i have sum and group the category amount.
how can i count the margin if i want to have option too see by month or by year.
Country Year Month Total
Australia 2018 December 80000
Australia 2018 February 50000
China 2018 March 20000
India 2018 March 40000
January 31, 2019 at 7:53 pm
girl_bj - Thursday, January 31, 2019 6:52 PMi would like to count margin by category.
i have sum and group the category amount.
how can i count the margin if i want to have option too see by month or by year.Country Year Month Total
Australia 2018 December 80000
Australia 2018 February 50000
China 2018 March 20000
India 2018 March 40000
this is my current query, is my calculation right here?
select year,month,country,total,[$]
,[$] / totalAll as [%]
from(
select year,month,country,total,totalAll
,totalAll-total as [$]
from(
select x.year,x.month,country,sum(total)total
from tableA x
inner join (select year,month,sum(total)totalAll from tableA y where y.year=year and y.month=month group by year,month)zz
on x.year=zz.year and x.month=zz.month
group by x.year,x.month,country
)a
)b
January 31, 2019 at 8:29 pm
girl_bj - Thursday, January 31, 2019 6:52 PMi would like to count margin by category.
i have sum and group the category amount.
how can i count the margin if i want to have option too see by month or by year.Country Year Month Total
Australia 2018 December 80000
Australia 2018 February 50000
China 2018 March 20000
India 2018 March 40000
What do you mean by "margin"? I'm confused. Margin is usually ([Cost] - [Price]) * [UnitsSold], right? Are you doing this in SQL Server? Because if you're doing this in DAX/Excel, then the answer is different.
January 31, 2019 at 8:37 pm
pietlinden - Thursday, January 31, 2019 8:29 PMgirl_bj - Thursday, January 31, 2019 6:52 PMi would like to count margin by category.
i have sum and group the category amount.
how can i count the margin if i want to have option too see by month or by year.Country Year Month Total
Australia 2018 December 80000
Australia 2018 February 50000
China 2018 March 20000
India 2018 March 40000What do you mean by "margin"? I'm confused. Margin is usually ([Cost] - [Price]) * [UnitsSold], right? Are you doing this in SQL Server? Because if you're doing this in DAX/Excel, then the answer is different.
Yes, im doing it in SQL.
January 31, 2019 at 8:56 pm
Okay, Can you post some sample data and expected output? I'm still not clear on what you're trying to do.
January 31, 2019 at 9:09 pm
pietlinden - Thursday, January 31, 2019 8:56 PMOkay, Can you post some sample data and expected output? I'm still not clear on what you're trying to do.
this is my current query, is my calculation right here? I would like to get the margin. Not so sure on the calculation.
select year,month,country,total,totalAll,[$]
,[$] / totalAll as [%]
from(
select year,month,country,total,totalAll
,totalAll-total as [$]
from(
select x.year,x.month,country,sum(total)total,totalAll
from #tableA x
inner join (select year,month,sum(total)totalAll from #tableA y where y.year=year and y.month=month group by year,month)zz
on x.year=zz.year and x.month=zz.month
group by x.year,x.month,country,totalAll
)a)b
January 31, 2019 at 9:12 pm
When I ran your query, it said it couldn't find the table...
And you never defined what you mean by Margin. Without TotalCost, how do you define Margin?
January 31, 2019 at 9:15 pm
pietlinden - Thursday, January 31, 2019 9:12 PMWhen I ran your query, it said it couldn't find the table...
And you never defined what you mean by Margin. Without TotalCost, how do you define Margin?
I push it to temp table.
The totalcost I sum it by month. Is that right?
January 31, 2019 at 9:21 pm
Since you never really explained what you're trying to accomplish, I have no idea.
If you want an answer, please read this article and follow the directions :Forum Etiquette: How to post data/code on a forum to get the best help
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply