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
)
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", "" )
)
)
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
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
)
)
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
)