The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I've been trying for several days to calculate the measures to determine how much a company (ticker) "contributes" to the index. For example, if an index grew by 30% in a year, how much comes from each company? 4% for ABCD, 10% from XYZW and 16% from XPTO.
I have a table with the following columns:
reference_date, ticker, weight, value_variation
The daily performance of the index composed of these companies is calculated as follows:
it would be the sum(value_variation * weight) divided by the sum(weight) on that date.
The cumulative performance of this index is calculated as follows:
What I would like to calculate is how much each ticker contributes to this cumulative performance. The formula to calculate this on a given date would be:
(cumulative performance up to that date) * (ticker's value_variation on that date * ticker's weight on that date divided by the total weight on that date) / (index performance on that date).
Then the sum of all these contributions on each date is the total contribution of that ticker.
Which I calculate as follows:
weight_index is this measure:
weight_index =
VAR TotalWeight = CALCULATE(SUM('COMPOSICAO_DIARIA_INDICES'[weight]), ALLEXCEPT('COMPOSICAO_DIARIA_INDICES', 'Calendario'[Date]))
RETURN DIVIDE(SUM('COMPOSICAO_DIARIA_INDICES'[weight]), TotalWeight)
What I'm doing seems to work if I don't apply any filter by ticker. But if I use a filter by ticker, the values don't change. For example, if I select only one ticker and its performance over the period was 20%, then its contribution should also be 20%, since it is the only one selected, but the calculated value is the same with all tickers
Hi,
Share some data to work with and show the expected result in a Table format. Share data in a format that can be pasted in an MS Excel file. If possible, please show the column headings in English.
Of course, here is an Excel file with 5 days of data:
https://docs.google.com/spreadsheets/d/19Lpfi-RaovDqNgOCzi58mjzDl6YJdj5f/edit?usp=drive_link&ouid=11...
Additionally, here is the expected result:
https://docs.google.com/spreadsheets/d/1oz8CxdVENIoDobdXbzOceM7u5tU00_MI/edit?usp=drive_link&ouid=11...
If it helps you, this is the Python code that I used:
Hi,
In the same_data file itself, show the formula driven result in Tab2. I will translate those Excel formulas to DAX formulas.
User | Count |
---|---|
79 | |
73 | |
39 | |
30 | |
28 |
User | Count |
---|---|
108 | |
99 | |
55 | |
49 | |
46 |