the problem is your data is not normalised
you need to use a union query to get the relevant data into a normalised form, then you can do your grouping
Something like
Code:
SELECT "Cost" as TranType, T_Furniture.Date_Bought as TDate, T_Furniture.Furniture_Cost as TValue
FROM T_Furniture
UNION SELECT "Revenue", T_Furniture.Date_Sold, T_Furniture.Furniture_Revenue
FROM T_Furniture;
call this Qry1
then you can use a crosstab query
Code:
TRANSFORM Sum(Qry1.TValue) AS SumOfTValue
SELECT Format([TDate],"yyyy-mm") AS yyyymm, Sum([tvalue]*IIf([trantype]="Cost",-1,1)) AS Net
FROM Qry1
GROUP BY Format([TDate],"yyyy-mm")
PIVOT Qry1.TranType
which produces this result
yyyymm |
Net |
Cost |
Revenue |
|
0 |
|
0 |
2021-10 |
0 |
0 |
|
2021-11 |
-30 |
30 |
|
2021-12 |
240 |
10 |
250 |
2022-01 |
140 |
160 |
300 |
2022-02 |
-90 |
90 |
|