How to divide day hours from night hours between 2 time fields - if-statement

I need to separate night hours and day hours between 2 times, if the time is between 6:00 am to 6:59 pm it should be day time and if the time is between 7:00 pm and 5:59 am it should be night time. Then I need to multiply night time by 1.25 and add it to day time if any.
I have tried with this formula but it seems to complex and sometimes it does not work
H4=if(G4 = 0,0,IF(AND(E4 > = TIME(19 , 0 , 0),F4 < = TIME( 6 , 0 , 0)), 0 ,IF(and(E4 < TIME(19 , 0 , 0),F4 < = TIME( 6 , 0 , 0)),F4-TIME(6, , ),IF(and(AND(E4 > = TIME(19, 0 , 0),F4>TIME(6, 0 ,0)),F4 < = TIME(19,0 , 0)),F4 - TIME(6 , 0 , 0 ),IF(and(and(E4 < TIME(19, 0 , 0 ),F4 > = TIME(6 , 0 , 0)),E4<TIME(6 , , )),F4 - TIME(6 , ,),IF(and(E4 < TIME(19 , , ),F4 < TIME(19 , , )), F4 - E4,IF(AND(E4 > = TIME(19 , 0 , 0 ),F4 < = TIME(23 ,59 ,0 )), 0 ,IF(E4 < TIME( 19 , 0 , 0 ),TIME( 19 , 0 , 0 ) - E4 , 0 ))))))))
I have the following structure:
G4=(F4-E4+(F4 < E4))
E4 is my start time ex: 11:01:00 PM
F4 is my end time ex 1:35:00 AM
Is there an easier way to get the division between times as to get the time I have to then do I4=G4-H4

delete everything in G4:I range
paste this into G4 cell:
=ARRAYFORMULA(IF(F4:F<>"", TEXT(F4:F-E4:E+(F4:F<E4:E), "[h]:mm:ss"), ))
paste this into H4 cell:
=ARRAYFORMULA(IF(F4:F>E4:E, TEXT((F4:F-E4:E)+
IF(E4:E-0.25>0,, E4:E-0.25)+
IF(0.7916666667-F4:F>0,, 0.7916666667-F4:F),
"[h]:mm:ss"),""))
paste this into I4 cell:
=ARRAYFORMULA(IF((G4:G<>"")*(G4:G<>H4:H), TEXT(G4:G-H4:H, "[h]:mm:ss"), ))

Related

PowerBI: Conditional Column - Check if the same item was there in the previous month

In PowerBI I have a dataset comprised of customer numbers (C1, C2, C3, ...) and dates when they placed their orders.
In the query I now want to add a custom column that gives me a 1 if the customer number appeared at least once in the previous month and a 0 if it didn't.
Customer_Number
Date
In_prev_month
C1
01.01.2022
0
C2
01.01.2022
0
C3
01.01.2022
0
C2
01.02.2022
1
C3
01.02.2022
1
C4
01.02.2022
0
add this as a calculated column (be aware that it is checking the previous date only not the month but it seems your database structure fits in)
In_prev_month 2 =
VAR _customer = 'Table'[Customer_Number ]
VAR _date = 'Table'[Date ]
RETURN
IF (
CALCULATE (
COUNT ( 'Table'[Customer_Number ] ),
FILTER (
ALL ( 'Table' ),
_date > ( 'Table'[Date ] )
&& _customer = ( 'Table'[Customer_Number ] )
)
) > 0,
1,
0
)

how to get running sum/cumulative sum of a measure in power bi using DAX (direct query)

i have simple dataset like below where the delta is a measure (not a column) which is the diff of demand and supply.I wanted to calculated the running sum of measure "delta" as shown below.running sum needs to be at material-location-week level.
dax i tried:
Cum =
var mat = MAX('table'[Material])
var pla = MAX('table'[Plant])
var pw =MAX('table'[PWk])
return
CALCULATE(
table[delta],
FILTER(
ALL(table),
'table'[Material]= mat && 'table'[Plant] <= pla && 'table'[PWk]<=pw
)
))
<>
material location week demand supply delta(demand-supply) running_sum??
123 1000 wk1 100 40 60 60
123 1000 wk2 40 30 10 70
123 2000 wk1 30 20 10 10
123 2000 wk2 40 15 25 35
please help. I am stuck with this and dont know`enter code here` where i am going wrong.
Perhaps:
running_sum =
VAR Mat =
MAX ( 'Table'[material] )
VAR Loc =
MAX ( 'Table'[location] )
VAR Wk =
MAX ( 'Table'[week] )
RETURN
CALCULATE (
[delta],
FILTER (
ALL ( 'Table' ),
'Table'[material] = Mat
&& 'Table'[location] = Loc
&& 0 + SUBSTITUTE ( 'Table'[week], "wk", "" )
<= 0 + SUBSTITUTE ( Wk, "wk", "" )
)
)

Write the elements of an array to file where each element is on its own line in Fortran

I wrote some code to print out the elements of a 3d-array where each element of the array is printed to a new line on screen. That worked (see output below).
Can anyone help me write a format statement that can produce the same thing in a file? (i.e. using WRITE(*,1200) and 1200 FORMAT() etc)?
Here is my code:
PROGRAM test_3d_array
IMPLICIT NONE
integer :: matrix(3,3,3), i, j, k ! three dimensional real array
integer :: CORE, CON, ALPHA
CORE = 3
CON = 3
ALPHA = 3
!assigning some values to the array matrix
do i=1,ALPHA
do j = 1,CORE
do k = 1,CON
matrix(i, j, k) = i+j+k
end do
end do
end do
!display the values
do i=1,ALPHA
do j = 1, CORE
do k=1,CON
WRITE(*,*) "MATRIX (", i, ",", j, ",", k, ") = ", matrix(i,j,k)
end do
end do
end do
END PROGRAM test_3d_array
Here is the screen output that I want to reproduce in the file:
MATRIX ( 1 , 1 , 1 ) = 3
MATRIX ( 1 , 1 , 2 ) = 4
MATRIX ( 1 , 1 , 3 ) = 5
MATRIX ( 1 , 2 , 1 ) = 4
MATRIX ( 1 , 2 , 2 ) = 5
MATRIX ( 1 , 2 , 3 ) = 6
MATRIX ( 1 , 3 , 1 ) = 5
MATRIX ( 1 , 3 , 2 ) = 6
MATRIX ( 1 , 3 , 3 ) = 7
MATRIX ( 2 , 1 , 1 ) = 4
MATRIX ( 2 , 1 , 2 ) = 5
MATRIX ( 2 , 1 , 3 ) = 6
MATRIX ( 2 , 2 , 1 ) = 5
MATRIX ( 2 , 2 , 2 ) = 6
MATRIX ( 2 , 2 , 3 ) = 7
MATRIX ( 2 , 3 , 1 ) = 6
MATRIX ( 2 , 3 , 2 ) = 7
MATRIX ( 2 , 3 , 3 ) = 8
MATRIX ( 3 , 1 , 1 ) = 5
MATRIX ( 3 , 1 , 2 ) = 6
MATRIX ( 3 , 1 , 3 ) = 7
MATRIX ( 3 , 2 , 1 ) = 6
MATRIX ( 3 , 2 , 2 ) = 7
MATRIX ( 3 , 2 , 3 ) = 8
MATRIX ( 3 , 3 , 1 ) = 7
MATRIX ( 3 , 3 , 2 ) = 8
MATRIX ( 3 , 3 , 3 ) = 9

Show total Minute Utilization for An hour in PowerBI report

I am trying to do log(ssrs execution log) analysis is powerbi. Requirement here is to show how many minutes utilized for a particular hour based on the request start & end time. Below is example for 4 requests Start & end time with expected result.
1st request 12:00 AM - 12:15 AM
2nd request 12:05 AM - 12:10 AM
3rd request 12:40 AM - 12:42 AM
4th request 12:41 AM - 12:48 AM
So total minute utilization for 12 AM hour should be 15mins(as first two requests overlap with each other) + 8mins (as last two also overlap for some mins) = 23 mins of total utilization at 12 AM.
Any help will be greatly appreciated.
I'd recommend splitting up the hour into 60 minutes and counting how many of the minutes are within the time frame of one of the requests.
Something like this logic for a calculated column:
Utilization =
VAR CurrentHour = HOUR ( Requests[Start] )
VAR Minutes =
GENERATESERIES (
TIME ( CurrentHour, 0, 0 ),
TIME ( CurrentHour + 1, 0, 0 ),
TIME ( 0, 1, 0 )
) /*This generates a column named [Value] with 61 rows
starting from the beginning of the hour.*/
RETURN
SUMX (
Minutes,
IF (
COUNTROWS (
FILTER (
Requests,
HOUR ( Requests[Start] ) = CurrentHour
&& Requests[Start] < [Value]
&& Requests[End] > [Value]
)
) > 0,
1,
0
)
)

DAX - Apply filters and check if the record is a particular category then output 1, else 0

I have a requirement like this,
P.No. BR IND SC TD RM CD PD Out - Col - Required
1 B N T 2/1/2011 2/1/2011 5/1/2007 1/1/2007 1
1 B N T 2/1/2011 2/1/2011 5/1/2010 2/1/2011 1
1 B N T 2/1/2011 6/1/2019 5/1/2007 2/1/2011 0
1 B N T 2/1/2011 1/1/2019 5/1/2007 2/1/2011 0
THE Out-Col-Required is what I am trying to do using DAX - Calculated Column.
This is the Logic that it follows,
Filter the Table for the following first in DAX,
BR = B, IND = N, SC = T, TD = RM
Then identify the Min CD date and Max PD date for P.No.
if the diff is less than 30 months, then 1 else 0.
Kindly help me with this.
Thanks.
Out =
VAR PNo = OutCol[P.No.]
VAR filt =
FILTER (
OutCol;
OutCol[P.No.] = PNo
&& OutCol[TD] = OutCol[RM]
&& OutCol[BR] = "B"
&& OutCol[IND] = "N"
&& OutCol[SC] = "T"
)
VAR monthsDiff =
CALCULATE (
DATEDIFF (
MIN ( OutCol[CD] );
MAX ( OutCol[PD] );
MONTH
);
filt
)
RETURN
IF (
OutCol[TD] = OutCol[RM]
&& OutCol[BR] = "B"
&& OutCol[IND] = "N"
&& OutCol[SC] = "T"
&& monthsDiff < 30;
1;
0
)