I have a problem in powerBI with DAX. I have the tables 'dim store', 'dim company' and 'fct storeValues' where 'dim store' and 'dim company' are connected and 'dim store' and 'fct storeValues' are connected. There are of course also other tables like a date table...
I have the measure 'rent' which sums the rent using the following syntax:
CALCULATE(SUM('fct storeValues'[value], 'fct storeValues'[type] = "rent"))
Now I would like to calculate the average per store grouped within the company. The SQL syntax I would be using would look something like this if calculated by year:
SELECT
Year, CompanyName, StoreName, Rent, AVG(Rent) OVER (Partition by CompanyName)
FROM (
SELECT
t1.Year, t3.CompanyName, t2.StoreName, sum(t0.value) as Rent
FROM
fctStoreData t0
inner join DimDate t1 on t1.Datum = t0.Datum
inner join DimStore t2 on t2.id = t0.standortId
inner join DimCompany t3 on t3.id = t2.kundeId
WHERE
t0.type = 'rent'
GROUP BY
t1.Year, t3.CompanyName, t2.StoreName
) agg
FROM agg
The exepected result would look something like this:
Company | StoreName | Year | Rent | AvgRent |
---|---|---|---|---|
A | 1 | 2023 | 1000 | 1500 |
A | 2 | 2023 | 1500 | 1500 |
A | 3 | 2023 | 2000 | 1500 |
B | 4 | 2023 | 2500 | 2000 |
B | 5 | 2023 | 1500 | 2000 |
C | 6 | 2023 | 3000 | 3000 |
D | 7 | 2023 | 1200 | 1425 |
D | 8 | 2023 | 1500 | 1425 |
D | 9 | 2023 | 1600 | 1425 |
D | 10 | 2023 | 1400 | 1425 |