Forum Discussion
Modifying a column value depending on index
v-eachen-msft Thanks for your answer! Sadly, it is not that simple. I can create a calculated column retaining 60% of the value from "Company A", and maintain all the rest. I cannot remove "Company ABC" because I need it as is extracted, just need to change this one value. I have two points to make:
First: The entire column of "Company A" must remain the same, I still need its full values if I want to analyse "Company A" by itself. Only when I need to analyse "Company ABC", is when I need it to count only 40% of "Company A".
Second: As noted, if I create a calculated column, identical to the original, but only with 60% of the values from "Company A", in the the table, this column would have different values only in the "Company A" rows, correct? All the rest would be identical. If I could place this 60% "Company A" values, on the same row as "Company ABC" values, side by side, I think it would be possible to simply subtract one from another, and I would get my result! Problem is: How do I write a calculated column, to give me 60% "Company A" results, on "Company ABC" rows? And if all the other values from Company A, B and C could be 0, the result would be perfect, cause it wouldn't impact the original column.
Maybe something like this:
| 1 | 01/01/2020 | Company A | Account 1 | 500 | 755 | 0 | 0 |
| 1 | 02/01/2020 | Company A | Account 2 | 700 | 1232 | 0 | 0 |
| 1 | 03/01/2020 | Company A | Account 3 | 150 | 675 | 0 | 0 |
| 1 | 04/01/2020 | Company A | Account 4 | 450 | 1401 | 0 | 0 |
| 2 | 01/01/2020 | Company A | Account 1 | 640 | 985 | 0 | 0 |
| 2 | 02/01/2020 | Company A | Account 2 | 620 | 941 | 0 | 0 |
| 2 | 03/01/2020 | Company A | Account 3 | 630 | 1088 | 0 | 0 |
| 2 | 04/01/2020 | Company A | Account 4 | 710 | 1320 | 0 | 0 |
| 1 | 01/01/2020 | Company B | Account 1 | 130 | 1050 | 0 | 0 |
| 1 | 02/01/2020 | Company B | Account 2 | 920 | 1372 | 0 | 0 |
| 1 | 03/01/2020 | Company B | Account 3 | 540 | 936 | 0 | 0 |
| 1 | 04/01/2020 | Company B | Account 4 | 570 | 845 | 0 | 0 |
| 2 | 01/01/2020 | Company B | Account 1 | 420 | 733 | 0 | 0 |
| 2 | 02/01/2020 | Company B | Account 2 | 750 | 1182 | 0 | 0 |
| 2 | 03/01/2020 | Company B | Account 3 | 820 | 906 | 0 | 0 |
| 2 | 04/01/2020 | Company B | Account 4 | 590 | 678 | 0 | 0 |
| 1 | 01/01/2020 | Company C | Account 1 | 260 | 426 | 0 | 0 |
| 1 | 02/01/2020 | Company C | Account 2 | 840 | 1385 | 0 | 0 |
| 1 | 03/01/2020 | Company C | Account 3 | 730 | 1518 | 0 | 0 |
| 1 | 04/01/2020 | Company C | Account 4 | 290 | 1140 | 0 | 0 |
| 2 | 01/01/2020 | Company C | Account 1 | 500 | 674 | 0 | 0 |
| 2 | 02/01/2020 | Company C | Account 2 | 660 | 952 | 0 | 0 |
| 2 | 03/01/2020 | Company C | Account 3 | 780 | 892 | 0 | 0 |
| 2 | 04/01/2020 | Company C | Account 4 | 70 | 326 | 0 | 0 |
| 1 | 01/01/2020 | Company ABC | Account 1 | 890 | 2231 | 300 | 453 |
| 1 | 02/01/2020 | Company ABC | Account 2 | 2460 | 3989 | 420 | 739,2 |
| 1 | 03/01/2020 | Company ABC | Account 3 | 1420 | 3129 | 90 | 405 |
| 1 | 04/01/2020 | Company ABC | Account 4 | 1310 | 3386 | 270 | 840,6 |
| 2 | 01/01/2020 | Company ABC | Account 1 | 1560 | 2392 | 384 | 591 |
| 2 | 02/01/2020 | Company ABC | Account 2 | 2030 | 3075 | 372 | 564,6 |
| 2 | 03/01/2020 | Company ABC | Account 3 | 2230 | 2886 | 378 | 652,8 |
| 2 | 04/01/2020 | Company ABC | Account 4 | 1370 | 2324 | 426 | 792 |
Hi Anonymous ,
Accoding to your expect result, I used RANKX() functino to create some groups based on an extra index column( you need to create it in the query editor ).
rank =
RANKX (
FILTER ( 'Table', 'Table'[Column3] IN { "Company A", "Company ABC" } ),
'Table'[Index],
,
ASC,
DENSE
)
Then use EARLIER() function return the result.
Result 1 =
VAR a =
CALCULATE (
FIRSTNONBLANK ( 'Table'[Column5], 1 ),
FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[rank] ) - 8 )
) * 0.6
RETURN
IF ( 'Table'[Column3] = "Company ABC", a, 0 )
Here is the final table.
Here is my test file for your reference.
- Anonymous6 years agoNot applicable
Hello v-eachen-msft Thank you for helping me out! The code is beggining to look like exactly what I need, in the example it works just fine! I still need something more to it, because I have two problems with this code on my real data:
I can't have something like 'Table'[rank] - 8 in the code, because its a growing table, positions might change. Sometimes, there are company A rows followed by company B, and then A again (although this could be changed when classifying a column by asc,desc), but still, the -8 would be a problem, I need it to be as automatic as possible, as every month, new data is added, and it already has over 100.000 rows
One other thing, "Company ABC" might have accounts that Company A doesn't! This happens if other companies have despenses/expenditures/profits on other things than Company A (although, most of the accounts are the same)
I have no problem creating an index in the query, maybe if we used another function other than RankX, it would be better to do what I need? I dunno, a column from 1 to X indexing every row in company A, 0 for others, and from X to Y indexing every row in Company ABC? Or a column having matching index for identical Accounts and Fontes for Company A and Company ABC? Im really having trouble trying to work this out, but im very thankful for ur help so far 😃