I am trying to create a calculated column in power BI called most recent score that gives me the most recent score for each employee.
Employee Number Date Score Most recent score
1234 01/01/2019 1 1
1235 01/01/2019 4 2
1236 01/01/2019 2 3
1288 01/01/2019 0 0
1259 01/01/2019 0 1
1234 01/02/2019 3 1
1235 01/02/2019 4 2
1236 01/02/2019 1 3
1288 01/02/2019 2 0
1259 01/02/2019 4 1
1234 01/03/2019 1 1
1235 01/03/2019 2 2
1236 01/03/2019 3 3
1288 01/03/2019 0 0
1259 01/03/2019 1 1
1234 01/04/2019 BLANK 1
1235 01/04/2019 BLANK 2
1236 01/04/2019 BLANK 3
1288 01/04/2019 BLANK 0
1259 01/04/2019 BLANK 1
I am using the below measure which seems to work unless the most recent score is a "0" in which case it pulls through the most recent non "0" score.
Most Recent Score =
VAR MRSM = Master[Employee ID]
RETURN
CALCULATE (
LASTNONBLANK ( Master[Score], Master[Score] ),
FILTER ( Master, Master[Employee ID] = MRSM )
)
Any help would be appreciated
EDITED ANSWER
This seems to do what you need.
Most Recent Score =
VAR EmpID = 'Master'[Employee ID]
VAR tblScores =
FILTER ('Master', 'Master'[Employee ID] = EmpID && NOT ( ISBLANK ( 'Master'[Score] ) )
)
VAR mrsDate = CALCULATE ( MAX ( [Date] ), tblScores )
RETURN
CALCULATE ( MAX ( 'Master'[Score] ), FILTER ( tblScores, 'Master'[Date] = mrsDate )
)
Related
I'm trying to calculate cumulative completion rate by all users over moths, the issue is that in the below table for ex when I filter on october it divides users who finished till october / all users except those who finished in November.
I have a dim_date table which is connect to the data table, the retaltion is between Date from dim_date and Completion Date from Data table
Also in dim date table im numbering the months 1,2,3,4 etc
ID
Completion_status
Completion Date
1
0
2
0
3
0
4
0
5
0
6
1
11/1/2022
7
1
11/1/2022
8
1
11/1/2022
9
1
11/2/2022
10
1
11/1/2022
11
1
11/6/2022
12
1
11/4/2022
13
1
11/2/2022
14
1
10/13/2022
15
1
10/14/2022
16
1
10/14/2022
17
1
10/13/2022
18
1
10/15/2022
19
1
10/13/2022
20
1
10/13/2022
21
1
10/13/2022
22
1
10/13/2022
23
1
10/18/2022
24
1
10/13/2022
25
1
10/13/2022
26
1
10/13/2022
27
1
10/13/2022
28
1
9/10/2022
29
1
9/8/2022
the formula I use
Completion% =
VAR comp rate = SUM(Table[completion_status]) / count(Table[ID])
Return
CALCULATE(Table[Completion%],filter(ALL(Dim_Date),Dim_Date[Month Number] <= MAX(Dim_Date[Month Number])))
the expected result when I filter
on september is 2/29 = 7%
on october is 16/29 = 55%
on November is 24/29 = 83%
Something like:
=
VAR SelectedMonth =
MIN( Dim_Date[Month Number] )
VAR CumulativeTotal =
CALCULATE(
COUNTROWS( 'Table' ),
FILTER(
ALL( Dim_Date ),
Dim_Date[Month Number] <= SelectedMonth
&& NOT ( ISBLANK( Dim_Date[Month Number] ) )
)
)
VAR CountAllRows =
CALCULATE( COUNTROWS( 'Table' ), ALL( Dim_Date ) )
RETURN
DIVIDE( CumulativeTotal, CountAllRows )
I'm presuming that Dim_Date[Month Number] is blank when Table[Completion Date] is blank.
You may want to replace ALL with, for example, ALLSELECTED, depending on your required set-up.
I am trying to add a calculated column which sums up per account no. Then I am trying to rank these as per account group separately.
First I tried to create the Total per Account column as
sub_total =
sumx(filter(all('Mizan Full'),'Mizan Full'[Account No] = EARLIER('Mizan Full'[Account No])),'Mizan Full'[Total])
this one is ok but :
then how can i give the ranks column as grouped by another column ?
rankx(allselected('Mizan Full'),'Mizan Full'[sub_total],,0)
or
RANKX(filter(('Mizan Full'), 'Mizan Full'[Account Group]= EARLIER('Mizan Full'[Account Group])), 'Mizan Full'[sub_total],,,Dense)
what am i doing wrong ?
Account Group
Account No
Total
sub_total
Rank per Group
120
120.01.C8716
-15.924,00
2.890.730,00
1
120
120.01.C8716
2.906.654,00
2.890.730,00
1
120
120.01.C8717
-290.733,00
-274.809,00
2
120
120.01.C8717
15.924,00
-274.809,00
2
159
159.01.003
108.475,00
108.475,00
1
335
335.01.C16805
3.238.202,00
3.238.202,00
1
335
335.01.C16808
2.154.455,00
2.154.455,00
2
335
335.01.C16807
290.733,00
290.733,00
3
335
335.01.C16806
2.154.455,00
-
4
335
335.01.C16806
-2.154.455,00
-
4
335
335.01.C15052
-1.500,00
-1.500,00
5
335
335.01.C16809
-70.911,00
-70.911,00
6
335
335.01.C16810
-70.911,00
-70.911,00
6
335
335.01.C16811
-89.000,00
-89.000,00
7
393
393.02.002
-70.911,00
-70.911,00
1
393
393.02.001
-70.911,00
-191.284,00
2
393
393.02.001
-70.911,00
-191.284,00
2
393
393.02.001
-70.911,00
-191.284,00
2
393
393.02.001
15.924,00
-191.284,00
2
393
393.02.001
5.525,00
-191.284,00
2
Edit :
I am attaching the sample file. I think I am almost there but I dont understand why
under group 335 - zero value must get rank 4 but it gets rank 8 and rank 4 is missing
under group 120 - listed as rank 2 and rank 4 but it should be 1 & 2
under group 393 - listed as rank 1 and rank 10 ???
Sample File
I solved it by adding a new table and measure but i am sure there is a better way...
Table :
MeasureTablo =
SUMMARIZECOLUMNS (
'Table'[Account Group ],
'Table'[Account No ],
"Toplam", SUM ( 'Table'[Total ] )
Measure :
Sira No =
RANKX (
FILTER (
ALLSELECTED ( MeasureTablo ),
MeasureTablo[Account Group ] = EARLIER ( MeasureTablo[Account Group ] )
),
( MeasureTablo[Toplam] ),
,
,
DENSE
)
My test tabe in powerbi:
IdRecord
Date
Value
1
2022-04-25 23:45:00.000
100
1
2022-04-24 18:07:00.000
344
2
2022-05-01 23:45:00.000
5
2
2022-05-02 18:07:00.000
66
2
2022-05-03 18:07:00.000
31
I require to create a calculated column to mark the earliest of the records grouped by id.
Desired output
IdRecord
Date
Value
IsFirst
1
2022-04-25 23:45:00.000
100
0
1
2022-04-24 18:07:00.000
344
1
2
2022-05-01 23:45:00.000
5
1
2
2022-05-02 18:07:00.000
66
0
2
2022-05-03 18:07:00.000
31
0
Answering to myself
FirstRes= VAR MYMIN = CALCULATE(
MIN(Table[Date]),
FILTER ( Table, Table[IdRecord] = EARLIER(Table[IdRecord]))
)
RETURN
IF(CALCULATE(
MIN(MIN(Table[Date]),MYMIN),
FILTER ( Table, Table[IdRecord] = EARLIER ( Table[IdRecord] ) )
) = Table[Date],1,0)
Need help in creating measures that will reflect the actual count of rows in the table when filtered.
Example:
ID
RankC
RankA
Avg Diff
RankC_count
RankA_count
Avg Diff_count
1000
AAA
XYZ
+01.00 to +01.25
5
6
4
1001
AAA
ZY1
+01.5.00 to +01.75
5
1
5
1002
AAB
XYZ
+01.5.00 to +01.75
3
6
5
1003
AAB
ZY2
+01.5.00 to +01.75
3
1
5
1004
AAB
XYZ
+01.00 to +01.25
3
6
4
1005
AAA
XYZ
+01.00 to +01.25
5
6
4
1006
AAA
ZY3
+01.00 to +01.25
5
1
4
1007
AAC
XYZ
+01.25.00 to +01.5
1
6
2
1008
AAA
ZY4
+01.25.00 to +01.5
5
2
2
1009
AAZ
ZY4
+01.5.00 to +01.75
1
2
5
1010
ABY
XYZ
+01.5.00 to +01.75
1
6
5
The last 3 columns represent the count of each entry. If I use the measure such as below, it provides the correct count. However, when I use in the visual, filtering by ID, say ID 1000, I want it to show line 1 with 5,6, and 4 on the counts, instead of all 1.
Questions:
Is there any measure to give me the correct result? say summarize the table first then do a lookup?
is creating a column the only choice? I cannot create columns since I need 1000 of these calculated columns. whereas using measure, I can create 1000 in one go.
Thanks for any help.
AverageDiff_Count =
CALCULATE (
COUNTROWS (
FILTER ( '28Jun_1973', [Average Diff] = '28Jun_1973'[Average Diff] )
)
)
The ALL function is useful here. It removes filter context so that it uses the whole table instead of just the part in the current filter context.
AvgDiff_Count =
VAR CurrAvgDiff = SELECTEDVALUE ( '28Jun_1973'[Avg Diff] )
RETURN
COUNTROWS (
FILTER ( ALL ( '28Jun_1973' ), '28Jun_1973'[Avg Diff] = CurrAvgDiff )
)
I'm working in a dashboard that control some kpis at my company. Now, I need to compare every result with the previous one, according to employee number. In the sample below, I show a little exemple of my data, and the expected result in the last column (previous score). I've tryed to solve that using a lot os calculated columns. I got close using the following:
PreviousScore =
VAR EMPNUMBER = BASE[Employee Number]
VAR REF = BASE[Score]
RETURN
CALCULATE(LASTNONBLANK(BASE[Employee Number];EMPNUMBER);FILTER(BASE;BASE[Employee Number]=EMPNUMBER);FILTER(BASE;BASE[Date]<EARLIER(BASE[Date])))
Employee Number Date Score Previous score
1234 01/01/2019 1 BLANK
1235 01/01/2019 4 BLANK
1236 01/01/2019 2 BLANK
1288 01/01/2019 0 BLANK
1259 01/01/2019 0 BLANK
1234 01/02/2019 3 1
1235 01/02/2019 4 4
1236 01/02/2019 1 2
1288 01/02/2019 2 0
1259 01/02/2019 4 0
1234 01/03/2019 1 3
1235 01/03/2019 2 4
1236 01/03/2019 3 1
1288 01/03/2019 0 2
1259 01/03/2019 1 4
1234 01/04/2019 2 1
1235 01/04/2019 3 2
1236 01/04/2019 8 3
1288 01/04/2019 BLANK 0
1259 01/04/2019 BLANK 1
I hope someone could help with this issue.
LW
You have no dependance between your dates, you pickup the earlier column and by accident they are in the right order.
The following query will give you the right result:
Previous score =
var empNR = score[Employee Number]
var theDate = score[Date]
var empData = FILTER(score;score[Employee Number] = empNR)
var prevDate = CALCULATE(MAX(score[Date]);empData;score[Date] < theDate)
return CALCULATE(MAX(score[Score]);FILTER(empData; score[Date] = prevDate))
I filter on emp number to get the data of that employee
I get the prevDate by getting the max of all dates which are lower
than selected date
last step is to get the one row and return the score