INDEX and AGGREGATE FUNCTION in Power BI - powerbi

I have a two tables are data and report.
In data table the following columns are Size A, Size B and Size C, Type and Rank.
In data table I created rank for each type based on the sizes. The purpose of the rank column were multiple matches for same size in this case the rank column will help to decide exact type were match more than one.
In report table the following columns are Size A, Size B and Size C.
In both table the Size A, Size B and Size C columns are common/relationship.
I am trying find out the appropriate type according to the Size A, Size B and Size C from data table into report table.
Data:
TYPE
SIZEA
SIZEB
SIZEC
RANK
A6
420
600
440
11.00
A4
640
600
480
9.00
A5
890
1100
1330
2.00
A6
1335
1100
2350
1.00
A7
890
1100
390
5.00
A8
890
1100
530
3.00
A9
670
1100
540
4.00
A10
670
1100
440
6.00
A11
320
1100
440
10.00
A12
600
400
400
12.00
A13
800
600
400
8.00
A14
1000
600
500
7.00
Report:
SIZEA
SIZEB
SIZEC
DESIRED RESULT-TYPE
400
300
140
A12
A12
250
250
160
A12
600
400
285
A12
400
300
150
A12
280
230
170
A12
320
320
320
A12
320
320
320
A12
600
400
140
A12
400
300
140
A12
400
300
140
A12
370
320
340
A12
320
240
250
A12
300
200
90
A12
400
290
140
A12
I am applying following formula in report table in order to get the appropriate type according to the Size A, Size B and Size C
=INDEX(DATA!$D$2:$D$16,AGGREGATE(15,6,(ROW(DATA!$H$2:$H$16)-1)/(DATA!$H$2:$H$16=1/(1/MAX(((DATA!$E$2:$E$16>=$B3)*(DATA!$F$2:$F$16>=$A3)+(DATA!$E$2:$E$16>=$A3)*(DATA!$F$2:$F$16>=$B3)>0)*(DATA!$G$2:$G$16>=$C3)*DATA!$H$2:$H$16))),1))
How can I apply the same logic in Power BI? Any advise please.
I am looking for new calculate column options. Herewith share the Excel file for your reference
https://www.dropbox.com/scl/fi/iq0gteeyazrg79q7a4tb1/AUTO-MODIFY-REQ.xlsx?dl=0&rlkey=nyyerjsg7if2dz30z9iqo6kdc

Here is another formula that will return the same result as per your current formula, although it is still a long formula, but more easily to understand:
=INDEX($D$2:$D$13,MATCH(MAX(IF($G$2:$G$13<$L3,0,
IF((IF($E$2:$E$13<$K3,0,1)*IF($F$2:$F$13<$J3,0,1))+(IF($E$2:$E$13<$J3,0,1)*IF($F$2:$F$13<$K3,0,1))>0,1,0))
*$H$2:$H$13),$H$2:$H$13,0),1)
So I will break it down to explain how do it working:
Part 1: This if formula is checking comparison of Size C, if your data is lower than than table, the value for the Type will be zero therefore will not be considered at all because zero times any amount will be zero
(IF($G$2:$G$13<$L3,0
Part 2: This part is will first checking comparison of Size A vs Size B, if lower than table than return 0 and apply for other comparison, at then end using If at the beginning to reset the value so than the final value will be 0 or 1
IF((IF($E$2:$E$13<$K3,0,1)*IF($F$2:$F$13<$J3,0,1))+(IF($E$2:$E$13<$J3,0,1)*IF($F$2:$F$13<$K3,0,1))>0,1,0)
Part 3: From the value you calculate, if 0 times any ranking will be zero, so from none zero ranking such as 12 or 9, it will get the max value from the list, most of them are 12
Max((.....)*$H$2:$H$13)
Part 4: Index Match - Finally it is same as your formula first part, but you are using Index row which make it difficult to understand
INDEX($D$2:$D$13,MATCH(Max(...))
A shorter version of your formula by removing unnecessary portion:
=INDEX($D$2:$D$13,MATCH(MAX(IF($G$2:$G$13<$L4,0,
IF(($E$2:$E$13>=$K4)*($F$2:$F$13>=$J4)+($E$2:$E$13>=$J4)*($F$2:$F$13>=$K4)>0,1,0))*$H$2:$H$13),
$H$2:$H$13,0),1)

You can add a colum to your report table like:
Desired = LOOKUPVALUE(DataR[TYPE],DataR[RANK], MAXX(FILTER(DataR, DataR[SIZEA] >= ReportR[SIZEA] && DataR[SIZEB] >= ReportR[SIZEB] && DataR[SIZEC] >= ReportR[SIZEC]), DataR[RANK]))
It first filters the table to find the row where the sizes are more or equal to the report row, selects the rank and then does a lookup to the type.
Result:

Related

DAX expression for sumarizing values to a set date

I have done some tests myself but all has been unsuccessful, but if I am missing something please feel free to ask for more information.
I have a spreadsheet with contract numbers on the rows and amortizations on the columns, like the following example:
Original Value
2011
2012
2013
2014
2105
1001
2000
10
10
10
10
10
1002
1500
20
20
20
20
20
1003
1200
0
0
15
15
15
1004
3000
0
0
0
0
10
Using DAX is there a good way to make a calculated value for the present value for each of the time frames? As the example below show:
Original Value
PV2101
PV2102
PV2103
PV2114
PV2105
1001
2000
1990
1980
1970
1960
1950
1002
1500
1480
1460
1440
1420
1400
1003
1200
0
0
1185
1170
1155
1004
3000
0
0
0
0
2990
So a calculated value that sums upp all prior amortizations dependant on the date in the x-axis and reduces that amount from the original value.
I can see two options:
You create a pivoted table:
|ID |Year|Value|
|----|----|----|
|1001|2011| 10|
|1001|2012| 10|
|1001|2013| 10|
|1001|2014| 10|
|1001|2015| 10|
|1002|2011| 20|
And then your measure will be trivial:
Calculated Value =
VAR dt_year = YEAR(SELECTED(date[date]))
RETURN SUM(table[Original Value]) +
CALCULATE(SUM(amort[Value]), amort[Year] <= dt_year)
Or you create some measure that adds up the individual columns:
Calculated Value =
VAR dt_year = YEAR(SELECTED(date[date]))
RETURN SUM(table[Original Value]) +
IF(dt_year >= 2011, SUM(table[2011]), 0) +
IF(dt_year >= 2012, SUM(table[2012]), 0) +
IF(dt_year >= 2013, SUM(table[2013]), 0) +
IF(dt_year >= 2014, SUM(table[2014]), 0) +
IF(dt_year >= 2015, SUM(table[2015]), 0)
Option 1 is a lot nicer.

Showing data in power Bi matrix as percentage

In the matrix, I have this representation -
X Y Z TOTAL
A 3 4 6 13
B 6 44 55 105
C 0 4 8 12
TOTAL 9 52 69 130
I want to show this as the following -
X Y Z
A 23% 31% 46%
B 6% 42% 52%
C 0% 33% 67%
example, for row A - (X/Total)*100 , (Y/Total)*100 ,(Z/Total)*100.
How do i do it?
Thanks in advance for your hep !
Select values field and show value as pecentage of row total

How to create 1000 files all the same but change some specific parameter?

I need to make around 1000 inputs files each is almost similar but change some parameters, how to create 1000 files all the same but change some specific parameter?
Is there a way to copy the file data and make it as output after I change a variable value?
========================================================================
=arp
ce16x16
5
3
0.2222222
0.2222222
0.2222222
60
60
60
1
1
1
0.71
ft33f001
end
#origens
0$$ a4 33 all 71 e t
ce16x16
3$$ 33 a3 1 27 a16 2 a33 18 e t
35$$ 0 t
56$$ 10 10 a6 3 a10 0 a13 4 a15 3 a18 1 e
95$$ 0 t
cycle 1 -fo3
1 MTU
58** 60 60 60 60 60 60 60 60 60 60
60 ** 0.02222222 0.04444444 0.06666667 0.08888889 0.1111111 0.1333333
0.1555556 0.1777778 0.2 0.2222222
66$$ a1 2 a5 2 a9 2 e
73$$ 922340 922350 922360 922380
74** 445 50000 230 949325
75$$ 2 2 2 2
t
====================================================================
This a part of the file, I would like to make 1000 files similar to this, but only change the values of 60 each time.
The value of 60 is equal some value entered by the user divider by (0.2222222).

Transform Ordered Values to Paired

I'm looking to transform a set of ordered values into a new dataset containing all ordered combinations.
For example, if I have a dataset that looks like this:
Code Rank Value Pctile
1250 1 25 0
1250 2 32 0.25
1250 3 37 0.5
1250 4 51 0.75
1250 5 59 1
I'd like to transform it to something like this, with values for rank 1 and 2 in a single row, values for 2 and 3 in the next, and so forth:
Code Min_value Min_pctile Max_value Max_pctile
1250 25 0 32 0.25
1250 32 0.25 37 0.5
1250 37 0.5 51 0.75
1250 51 0.75 59 1
It's simple enough to do with a handful of values, but when the number of "Code" families is large (as is mine), I'm looking for a more efficient approach. I imagine there's a straightforward way to do this with a data step, but it escapes me.
Looks like you just want to use the lag() function.
data want ;
set have ;
by code rank ;
min_value = lag(value) ;
min_pctile = lag(pctile) ;
rename value=max_value pctile=max_pctile ;
if not first.code ;
run;
Results
max_ max_ min_ min_
Obs Code Rank value pctile value pctile
1 1250 2 32 0.25 25 0.00
2 1250 3 37 0.50 32 0.25
3 1250 4 51 0.75 37 0.50
4 1250 5 59 1.00 51 0.75

How to compute characteristic vector in SAS proc anova

SAS code:
DATA aaa;
INPUT x1 x2 group ##;
CARDS;
3.9 210 1 4.8 270 2 4.4 250 3
4.2 190 1 4.7 180 2 3.7 305 3
3.7 240 1 5.4 230 2 2.9 240 3
4.0 170 1 4.5 245 2 4.5 330 3
4.4 220 1 4.6 270 2 3.3 230 3
5.2 230 1 4.4 220 2 4.5 195 3
2.7 160 1 5.9 290 2 3.8 275 3
2.4 260 1 5.5 220 2 3.7 310 3
3.6 240 1 4.3 290 2
5.5 180 1 5.1 310 2
2.9 200 1
3.3 300 1
;
PROC ANOVA ;
CLASS group;
MODEL x1 x2=group;
MANOVA H=group/PRINTH PRINTE SUMMARY;
RUN;
quit;
SAS output:
Characteristic Roots and Vectors of: E Inverse * H, where
H = Anova SSCP Matrix for group
E = Error SSCP Matrix
Characteristic Characteristic Vector V'EV=1
Root Percent x1 x2
0.64162782 75.19 0.23674984 0.00222702
0.21172068 24.81 -0.11171221 0.00402658
I used R to compute the eigenvalues and eigenvectors of E Inverse * H:
E=matrix(c(14.652666667,-53.58333333,-53.58333333,47426.041667),
nrow=2, ncol=2,byrow = TRUE)
E
H=matrix(c(7.926,122.48333333,122.48333333,13753.958333),
nrow=2, ncol=2,byrow = TRUE)
H
C=solve(E)%*%H
C
eigen(E)
The eigenvalues are same, but the eigenvectors are different with SAS characteristic vectors.
Can you tell me why or algorithms? Thank you!