This question already has answers here:
Conditional formatting based on another cell's value
(7 answers)
Closed 4 months ago.
Please help change color scale - conditional formatting
B2 = 60 (fixed value)
If B2 = 10 (daily count) then B2 = Green BG
(based on percentage - 1 to 60 )
Min = Green , Mid = Orange, Max and above = Red
Min = Green , Mid = Orange, Max and above = Red
literally, try:
1
30
60
update:
1
=(B2-(B3/B2))/1.1
=B2-(B3/B2)
Related
Hello I am just new in powerBI and it is still hard to work on for me.
I have a matrix like that
DATE Sales Refund
26 Agu 45 5
p1 10 3
p2 15 2
p3 20 0
27 Agu 60 1
p1 15 1
p2 20 0
p3 25 0
In the date parts I have subtotals as it normally does. However, I want to show the average of that day there and when I get the average I will make conditional formatting according to it. If a cell is below average I will mark it with red point and in refunds I will do it for the values above the average.
Is there a way to do that. I searched for it for awhile but could not find.
The output I want is like that. (star is for red point.)
DATE Sales Refund
26 Agu 15 1.66
p1 10* 3*
p2 15 2*
p3 20 0
27 Agu 20 0.33
p1 15* 1*
p2 20 0
p3 25 0
Thanks.
You can colour the background; For example, create this measure:
AVG =
IF( SELECTEDVALUE(RefundTab[Sale] ) < CALCULATE(AVERAGE(RefundTab[Sale]), ALL(RefundTab[Code])),0,1)
From menu -> Conditional formatting -> Background color:
And here:
OR
you can create measure where we return string instead of number where we put some unicode value:
SumSaleIf =
var _sale = sum(RefundTab[Sale])
var _IfAVG = CALCULATE(AVERAGE(RefundTab[Sale]), ALL(RefundTab[Code]))
var _check = if(_sale < _IfAVG, _sale & UNICHAR(128315), _sale &"")
return _check
This question already has an answer here:
How to use arrayformula with formulas that do not seem to support arrayformulas?
(1 answer)
Closed 4 months ago.
Using an array formula I want to find the max value of each row of a range and get the resulting range to work with it further.
The problem occurs as soon as I add the MAX() statement since it does seem to behave strangely within an array formula. Even if you ad commands which will give you multiple values within the MAX() statement it does always only return one single value.
E.g. this will give you the ranges which I want to get the max of:
=ARRAYFORMULA(ADDRESS(ROW(E1:E11); COLUMN() + 1; 4) & ":" & ADDRESS(ROW(E1:E11); COLUMN() + 4; 4))
The result looks like the following:
F1:I1
F2:I2
F3:I3
F4:I4
F5:I5
F6:I6
F7:I7
F8:I8
F9:I9
F10:I10
F11:I11
If I now add INDIRECT() to make those to actual ranges and add MAX() it should return the max of each of those ranges since the array formula should go through the ROW(E1:11) as it did bevor. However, the result of this new formula
=ARRAYFORMULA(MAX(INDIRECT(ADDRESS(ROW(E1:E11); COLUMN() + 1; 4) & ":" & ADDRESS(ROW(E1:E11); COLUMN() + 4; 4))))
rather is one single value, the maximum of the first range.
I have even tried to bypass the problem by adding an IF() statement for the array formula to iterate through the rows. Doing so, it did give me a result for all 11 rows, however, the result always was the same (the max of the first row).
The new formula:
=ARRAYFORMULA(IF(ROW(E1:E11) = ROW(E1:E11); MAX(INDIRECT(ADDRESS(ROW(E1:E11); COLUMN() + 1; 4) & ":" & ADDRESS(ROW(E1:E11); COLUMN() + 4; 4))); ""))
The new result (left column are the results of the formula, trying to get the max of each row to its right):
10 7 10 4 1
10 10 8 1 2
10 4 5 9 4
10 10 10 2 2
10 10 10 5 10
10 10 6 9 5
10 4 5 7 3
10 6 9 4 7
10 5 5 7 3
10 9 2 3 10
10 10 3 9 10
=QUERY(TRANSPOSE(QUERY(TRANSPOSE(F1:I),
"select "®EXREPLACE(JOIN( , ARRAYFORMULA(IF(LEN(F1:F&G1:G&H1:H&I1:I),
"max(Col"&ROW(F1:F)-ROW(F1)+1&"),", ""))), ".\z", "")&"")),
"select Col2")
I am trying to calculate the average of a column in a measure in DAX, but I have the problem that the values are duplicated on multiple rows.
The data looks like this:
Line ID Value
1 1 10
2 1 10
3 1 10
4 1 10
5 1 10
6 2 40
7 2 40
8 3 90
9 3 90
10 3 90
When I do
sum(data[Value]) / countrows(data)
the answer will be (50 + 80 + 270) / 10 = 40.
However, I want the answer to be (10 + 40 + 90) / 3 = 46.7
I know I have to divide by 3 and can achieve the 3 by
distinctcount(data[ID])
But I find it difficult to extract the 10, 40 and 90.
Can you help me?
There are many ways to achieve that. For example:
Average Value =
VAR Summarized_Table = SUMMARIZE ( Data, Data[ID], Data[Value] )
VAR Total_Value = SUMX ( Summarized_Table, Data[Value] )
VAR Total_Count = COUNTROWS ( Summarized_Table )
RETURN
DIVIDE ( Total_Value, Total_Count )
Result:
Explanation:
First, we create a summarized version of the data, by grouping it on ID and Value columns. Grouping eliminates duplication, so the summary table contains only 3 records. We save the table in a variable;
Second, we sum up values in the summary table (140);
Third, we count number of records in the summary table (3)
Finally, we return the result by dividing sum and count
Alternatively, you can do this:
Average Value =
AVERAGEX ( VALUES ( Data[ID] ), CALCULATE ( AVERAGE ( Data[Value] ) ) )
Result is the same, but the logic is different:
First, using VALUES we create a list of distinct IDs;
Second, we use AVERAGEX to iterate the list, and for each ID calculate its average value. For example, for ID=1, result will be Average of (50)/5= 10;
Finally, we average the averages as (10 + 40 + 90) / 3
my first attempt in VBA apart from using simple functions; asking for a kick start here:
assume this (part of a) sheet
factor b-count c-count d-count
A2 b2 c2 d2 ...
A3 b3 c3 d3 ...
Assume that these are the first columns and rows A1 to D3, holding numeric values each.
If factor is 1, I want A(N) (column 'A', row N >= 2) to hold the sumproduct of row 1 and row N.
The twist comes when factor is not 1. In that case I want a sumproduct of
count*round(value * factor).
Example:
1.5 2 1 0 4
=myfunc(2) 4 8 11 15
=myfunc(3) 11 20 28 36
=myfunc(4) 29 53 74 94
where myfunc(2) should result in
round(4*1,5)*2+round(8*1,5)*1+round(15*1,5)*4 = 6*2+12*1+23*4 = 12+12+92 = 116, myfunc(3) = 17*2+30+54*4 = 34+30+216 = 280, myfunc(4) = 44*2+80+141*4 = 88+80+564 = 732 etc.
I could just insert a row below each one, multiplying every value with the factor; but I would love something fancier.
basically thought (pun not intended):
col='B'
sum=0
do while (col)(N)>0
sum=sum+(col)(1)*round((col)(N)*A1;0)
col=col+1
loop
A(n)=sum
where (col)(N) refers to the cell in column col and row N.
Not important enough to study the manual; but it would be great if someone can do this off the cuff.
Another point: I have read that custom functions must be stored in the "Standard Library";
but I could not find any mention on HOW to do that. Who will point me to the right manual page?
Go to Tools -> Macros -> Organize Macros -> OpenOffice Basic. Select My Macros -> Standard -> Module 1 (that is what is meant by the Standard library), and press Edit.
Paste the following code.
Function SumProductOfTwoRows(firstColumn As Long, row As Long, firstRow As Long)
'For example: =SUMPRODUCTOFTWOROWS(COLUMN(); ROW(); ROW($A$1))
firstColumn = firstColumn - 1 'column A is index 0
row = row - 1 'row 1 is index 0
firstRow = firstRow - 1 'row 1 is index 0
oSheet = ThisComponent.CurrentController.ActiveSheet
sum = 0
column = firstColumn + 1
factor = oSheet.getCellByPosition(firstColumn, firstRow).getValue()
Do
value = oSheet.getCellByPosition(column, row).getValue()
count = oSheet.getCellByPosition(column, firstRow).getValue()
If value = 0 Then Exit Do
sum = sum + count * CLng(value * factor)
column = column + 1
Loop
SumProductOfTwoRows = sum
End Function
Enter this formula in A2 and drag to fill down to A4.
=SUMPRODUCTOFTWOROWS(COLUMN(); ROW(); ROW($A$1))
The result:
This kind of user-defined function produces an error when re-opening the file. To avoid the error, see my answer at https://stackoverflow.com/a/39254907/5100564.
I have two different rates that the user can make for his teacher , i want to convert the total of each rate in pixels so i can have the progress bar effect, for example:
maximum_pixels = 100 #maximum width
services = 4.5 #width: 95px
professionalism = 5.0 #width: 100px
total_percentage = maximum_pixels * services / maximum_pixels
How can i implement that in my code ?
maxAllowed = 100
minAllowed = 0
unscaledNum = 3
_min = 0
_max = 5
((maxAllowed - minAllowed) * (unscaledNum - _min) / (_max - _min) + minAllowed)
Result:
60.0