Ledgered fact vs average aggregation
3 posters
Page 1 of 1
Ledgered fact vs average aggregation
Suppose we have the fact table below:
Item,Sales
A,3
A,5
B,3
B,5
B,1
B,-1
Notice that item "B" has ledgered entries. The "B,-1" record is the soft delete of "B,1".
Now we want to calculate the average sales of items. Expected result:
Item,Average(Sales)
A,4
B,4
But the actual result is:
Item,Average(Sales)
A,4
B,2
How to properly calculate average aggregation for ledgered fact?
Item,Sales
A,3
A,5
B,3
B,5
B,1
B,-1
Notice that item "B" has ledgered entries. The "B,-1" record is the soft delete of "B,1".
Now we want to calculate the average sales of items. Expected result:
Item,Average(Sales)
A,4
B,4
But the actual result is:
Item,Average(Sales)
A,4
B,2
How to properly calculate average aggregation for ledgered fact?
adisutanto- Posts : 1
Join date : 2012-10-05
Re: Ledgered fact vs average aggregation
You don't have enough information. The question is: average what? Average for a day? Average for a transaction? etc...
It winds up being a two pass query. Assuming you have other dimensions, you need to net things out along the dimension you want the average of, then calculate the average of that set.
It winds up being a two pass query. Assuming you have other dimensions, you need to net things out along the dimension you want the average of, then calculate the average of that set.
Re: Ledgered fact vs average aggregation
Below SQL code should help you.
with cte AS
(
select item, abs(sales) sales from #temp
group by item, abs(sales)
having count(abs(sales)) > 1
)
select * from #temp
left outer join cte
on cte.item = #temp.item
and cte.sales = abs(#temp.sales)
where cte.item is null
with cte AS
(
select item, abs(sales) sales from #temp
group by item, abs(sales)
having count(abs(sales)) > 1
)
select * from #temp
left outer join cte
on cte.item = #temp.item
and cte.sales = abs(#temp.sales)
where cte.item is null
krvin- Posts : 1
Join date : 2012-05-03
Similar topics
» Aggregation of FACT during Many to Many relationship
» Derived fact tables, aggregation and views
» average price fact table
» Aggregation of facts, use as dimension
» Real Time Data Aggregation
» Derived fact tables, aggregation and views
» average price fact table
» Aggregation of facts, use as dimension
» Real Time Data Aggregation
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|