Sup, simple question ( i hope). I am adding a custom column in Power bi. I need to subtract time values, using custom column formula. Problem: (B-A)-C causes error.
Values are set to time type.
B = 15.00.00
A = 9.00.00
C = 0.05.00
custom column formula:
=([B]-[A])-[C]
Result i want: 5.55.55
Result i get:
Expression.Error: We cannot apply operator - to types Duration and Time.
Details:
Operator=-
Left=0.06:00:00
Right=0.05.00
So B-A = 0.06:00:00 and therefore 0.06:00:00 - 0.05.00 = error. I need to get B-A result in shape of 06.00.00 so i can subtract value C from it. Any suggestions?
Assuming your table is called "Table":
First, create a new column and calculate the difference of B and A.
Col1 = DATEDIFF(Table1[B],Table1[A],HOUR)
Then create another column and subtract C from it.
Col2 = DATEDIFF(Table1[Col1],Table1[C],HOUR)
Related
I have a column named Cur_bal in power bi I just want to know what day function could help me change all negative a to 0 and keep all other values the same.
You can use either a calculated column or a measure. The formula for a calculated column would be:
Cur_Bal - Positive_Only =
IF ( 'Table'[Cur_Bal] < 0, 0, 'Table'[Cur_Bal] )
Once you have that, you can use it in an implicit or explicit measure to sum up the total.
For a measure, it would look like this:
Cur_Bal - Positive_Only (measure) =
CALCULATE ( SUM ( 'Table'[Cur_Bal] ), 'Table'[Cur_Bal] > 0 )
The measure uses a CALCULATE function with a simple filter on Cur_bal column.
Link to image of output sample table...
I have a dataframe with 3,000,000 IDs. Each ID has the month range from 2015-01-01
t0 2018-12-01. Each ID has column "A" and "B" with numeric values. I need to create a new column "C:.
For each ID, when Date == '2015-01-01' which is the first month for that ID, column C value equal to exp(column_A value).
For the next month (Date == '2015-02-01'), column C value equal to exp(log(column_C_value in previous month) + column_B_value at this month), so here is exp(log(column C # 2015-01-01) + column_B # 2015-02-01). Each of the following months has the same pattern until it reaches 2018-12-01.
In Python, I can setup the loop for each ID and for each row/month, such as:
for ID in range(xxx):
for month in range(xxxx):
However, such calculation takes long time. Can anyone tell me a faster way to do this calculation? Very appreciated for your help!
Consider that
(1) exp(x+y) == exp(x)*exp(y).
And
(2) exp(log(x)) == x.
So exp(log(c1) + b2) == c1 * exp(b2).
The next value simplifies to c1 * exp(b2) * exp(b3), and so on.
That means, you have to multiply all exp(b) values, which can be turned
into adding all(b)-s and then applying exp() to the result.
And don't forget to multiply it with a1, the initial value.
a1 * exp(b2 * b3 * ...)
I'm new to Power BI so I may have titled this wrong but I'm trying to use a SUMPRODUCT in my table but the total is incorrect.
My goal is to take the SUMPRODUCT of (Linear_Feet_Out,Hrs) / SUM(Linear_Feet_Out)
So I broke it down to try and solve the problem but am having no luck. Slitting_Time_New is just my est field to make sure each row is calculating correctly. So 2.000 * 226,795 = 453,589
However the results I am expecting are 2.54 in the "Slitting_Time_Avg" field total.
Here is what I have so far:
Slitting_Time_Avg =
VAR Numerator = [Slitting_Time_New]
VAR Denominator =
SUM (Mfng_Analysis[Linear_Footage_Out] )
RETURN
CALCULATE ( DIVIDE ( Numerator, Denominator ) )
But I want it to take the sum of Slitting_Time_New (a calc measure), not the 8,719,451.50
Slitting_Time_New = SUM(Mfng_Analysis[Hrs])*SUM(Mfng_Analysis[Linear_Footage_Out])
This is due to evaluation context. When using the SUM function, DAX has no row context, unless you actively provide it in a visual table, i.e. for the Total row in your table [Slitting_Time_New] will evaluate
(2,000+2,900+0,800)x(226795+1136807+166127).
What you want to do, I guess, is
(2,0000x226795)+(2,900x1136807)+(0,800x166127)
In order to do that you have to provide row context. This you can do with an aggregator function, such as SUMX.
Slitting_Time_New =
SUMX(
Mfng_Analysis;
[Hrs]*[Linear_Footage_Out]
)
Is it possible to have a range of values in a cell so that Sheets understands it when calculating something?
Here's an example of the desired output:
A B C
1 Value Share Total sum
2 100.00 90-110% 90-110
Here, Total sum (C2) = A2 * B2 (so 100 * 90-110%), giving a range of 90-110.
However, I don't know how to insert this range of values into a cell without Sheets saying #VALUE!.
you will need to do it like this:
=REGEXREPLACE((A2*REGEXEXTRACT(B2, "\d+")%)&"-"&
A2*REGEXEXTRACT(B2, "-(\d+%)"), "\.$", )
for decimals:
=REGEXREPLACE((A40*REGEXEXTRACT(B40, "\d+.\d+|\d+")%)&"-"&
A40*REGEXEXTRACT(B40, "-(\d+.\d+%)|-(\d+%)"), "\.$", )
I have three columns. One identifies the observations by F. The other column orders each observation within the same F, called T. The third column is a numerical value, called Q. I'd like all my values for Q greater than a certain value of T to be replaced by the values at a fixed T, within the same F. For example, I'd like all values of Q within the same F that have T > 6 to be equal to whatever value Q has for that F has for T = 6. If an F has a Q value of 40 at T=6 and a Q value of 50 at T=7, I want that Q at T=7 to say 40 as well.
This might not be the correct way of solving this, but it did the trick. If anyone has a better solution, please help me out.
xtset F T
gen Q_fixed = Q
replace Q_fixed = . if T > 6
replace Q_fixed = L.Q_fixed if Q_fixed == .