I am new to PowerBi and would need some help figuring out how to make the percentile.exc function work (I cannot use percentile.inc).
I systematically receive the following error: The percentile value should be in the range 1/(N+1)..N/(N+1) inclusive, where N is the number of data values.
The objective of this code is to compute the 3months rolling 90th percentile of a given ratio in another calculated column.
I would be very grateful for any help!
This is what I have come with up so far:
3MonthsRolling_90thPercentile=
VAR current_date = Table1[Date]
VAR k = 0.9
VAR NumValues =
COUNT (Table1[Ratio] )
VAR LowerBound = 1 / ( NumValues + 1 )
VAR UpperBound = NumValues / ( NumValues + 1 )
RETURN
CALCULATE (
IF (AND ( PERCENTILE.EXC ( Table1[Ratio],0.9) >= LowerBound, PERCENTILE.EXC (Table1[Ratio],0.9) <= UpperBound ),PERCENTILE.EXC ( Table1[Ratio],0.9), BLANK()),
FILTER (
ALL (Table1 ),
Table1[Date]
>= DATE ( YEAR ( current_date ), MONTH ( current_date ) - 3, DAY ( current_date ) )
&& Table1[Date] <= current_date
)
)
If NumValues is less than 9 in, then 0.9 is above your upper bound NumValues / ( NumVales + 1 ), so PERCENTILE.EXC ( Table1[Ratio], 0.9 ) will throw an error.
I think your measure would make more sense as follows:
3MonthsRolling_90thPercentile =
VAR current_date = Table1[Date]
VAR DateFiltered =
FILTER (
ALL ( Table1 ),
Table1[Date]
>= DATE (
YEAR ( current_date ),
MONTH ( current_date ) - 3,
DAY ( current_date )
)
&& Table1[Date] <= current_date
)
VAR k = 0.9
VAR NumValues = CALCULATE ( COUNT ( Table1[Ratio] ), DateFiltered )
VAR LowerBound = 1 / ( NumValues + 1 )
VAR UpperBound = NumValues / ( NumValues + 1 )
RETURN
IF (
AND ( k >= LowerBound, k <= UpperBound ),
CALCULATE ( PERCENTILE.EXC ( Table1[Ratio], k ), DateFiltered )
)
Note that I'm comparing k to the bounds rather than the k-percentile.
Related
I want to show the TOP10 difference in a measure.
The difference is calculated YTD actual + Rest of the year forecast - Full year budget values.
The normal measure looks like this:
VAR _Year =
SELECTEDVALUE ( 'Calendar'[Year] )
RETURN
(
CALCULATE (
SELECTEDMEASURE (),
DATESYTD ( Calendar[Dates] ),
CRDB[Scenario] = "Actual",
ALL ( CRDB[ForecastTypeFinal] )
)
+ CALCULATE (
SELECTEDMEASURE (),
CRDB[Scenario] = "Forecast",
'Calendar'[Dates] >= DATE ( _Year, 1, 1 )
&& 'Calendar'[Dates] <= DATE ( _Year, 12, 31 )
)
)
- CALCULATE (
SELECTEDMEASURE (),
Calendar[Dates] >= DATE ( _Year, 1, 1 )
&& Calendar[Dates] <= DATE ( _Year, 12, 31 ),
CRDB[Scenario] = "Budget",
ALL ( CRDB[ForecastTypeFinal] )
)
I would like to rank by project, so I made this ranking measure:
RANKX (
ALL ( CRDB[Project ID - Project ID Level 01 (Text)] ),
(
CALCULATE (
SELECTEDMEASURE (),
DATESYTD ( Calendar[Dates] ),
CRDB[Scenario] = "Actual",
ALL ( CRDB[ForecastTypeFinal] )
)
+ CALCULATE (
SELECTEDMEASURE (),
CRDB[Scenario] = "Forecast",
'Calendar'[Dates] >= DATE ( SELECTEDVALUE ( 'Calendar'[Year] ), 1, 1 )
&& 'Calendar'[Dates] <= DATE ( SELECTEDVALUE ( 'Calendar'[Year] ), 12, 31 )
)
)
- CALCULATE (
SELECTEDMEASURE (),
Calendar[Dates] >= DATE ( SELECTEDVALUE ( 'Calendar'[Year] ), 1, 1 )
&& Calendar[Dates] <= DATE ( SELECTEDVALUE ( 'Calendar'[Year] ), 12, 31 ),
CRDB[Scenario] = "Budget",
ALL ( CRDB[ForecastTypeFinal] )
),
,
DESC
))
The ranking gets me the correct projects, but when I look at the rank values, they are not right:
ranking values
The values are not the same, so it is no reason for skipping places.
What do I do wrong?
Thank you for your help in advance.
I have a measure:
_Forecast, % =
VAR ForecastMinimumPercent = 10
VAR ForecastIncreasePercent = 15
VAR sM =
MAX ( T1[PlanDate] ) //Plan Date
VAR fM =
MAX ( '_Date2'[Date] ) //fact Date
VAR sC =
FIRSTNONBLANK ( T1[ProjectCode], 1 ) //Current project code
VAR tP =
//Current forecast cumulative percent
CALCULATE (
SUM ( T1[ForecastPercent] ),
FILTER (
ALLSELECTED ( 'T1' ),
T1[PlanDate] <= fM
&& T1[PlanDate] <= sM
&& T1[ProjectCode] = sC
),
REMOVEFILTERS ( T1[PlanDate] )
)
VAR mM =
// Current Project first Date
CALCULATE (
MIN ( T1[PlanDate] ),
FILTER ( ALLSELECTED ( 'T1' ), T1[ProjectCode] = sC ),
REMOVEFILTERS ( T1[PlanDate] )
)
VAR nD =
ROUNDUP ( DIVIDE ( 100 - tP, ForecastIncreasePercent, 0 ), 0 ) // count of forecast columns
VAR fD =
DATEDIFF ( sM, fM, MONTH ) //dates offsets, '_Date2'[Date] - T1[PlanDate]
VAR P1 = tP + ForecastIncreasePercent * fD //forecasted percent
VAR P2 =
IF ( P1 > 100, 100, P1 ) //does not show values over 100, for example 90+15=105 but show 100
VAR fP =
SWITCH (
TRUE (),
tP < ForecastMinimumPercent, BLANK (),
// if percent <10, then hide
fM < mM, BLANK (),
//hide values if T1[PlanDate] <> '_Date2'[Date]
MAX ( T1[ForecastPercent] ) = 0, BLANK (),
// hide empty percent rows
fM
> DATE ( YEAR ( sM ), MONTH ( sM ) + nD + 1, DAY ( sM ) ), BLANK (),
//does not show 100 more than once
fM <= sM, IF ( HASONEVALUE ( T1[PlanDate] ), BLANK (), tP ),
//if collapsed show first fact values
P2
)
RETURN
fP
This measure give me current forecast percent
But i need get difference current month - previous
How to write right syntax?
I have a measure in which i am dividing total number of contractual months from total number of months. I am getting correct result, but the total in the bottom is not correct.
The first column is a unique ID, Third and fourth columns are numerator and denominator, Second column is the result of the division, I want to count those IDs, where the division is between 0.75 and 1.00
Here are my calculations
Var Check=DIVIDE([Month of Engagement],[Months In Contract L30])
RETURN
IF(HASONEVALUE('Fact - TABLE'[ID]),IF(Check>=0.75 && Check<=1.00,DISTINCTCOUNT(ID),0),SUMX('Fact - TABLE',IF(Check>=0.75 && Check<=1.00,DISTINCTCOUNT(ID),0)))
Please let me know, how to solve this.
For Total, you should change 3th parameter of IF to:
CALCULATE (
SUMX (
CALCULATETABLE (
tab,
FILTER (
ALL ( tab ),
VAR __Check =
DIVIDE ( 'Tab'[Month of Engagement], Tab[Months In Contract L30] )
RETURN
__Check < 1
&& __Check > 0.75
)
),
1
)
)
Below my test example (for testing only I have put check variable in first IF
IF ( Check >= 0.75 && Check <= 1.00, Check, 0 ) to see if check calculation is correct):
Measure =
VAR Check =
DIVIDE (
SUM ( 'Tab'[Month of Engagement] ),
SUM ( Tab[Months In Contract L30] )
)
RETURN
IF (
HASONEVALUE ( 'Tab'[ID] ),
IF ( Check >= 0.75 && Check <= 1.00, Check, 0 ),
CALCULATE (
SUMX (
CALCULATETABLE (
tab,
FILTER (
ALL ( tab ),
VAR __Check =
DIVIDE ( 'Tab'[Month of Engagement], Tab[Months In Contract L30] )
RETURN
__Check < 1
&& __Check > 0.75
)
),
1
)
)
)
Measure =
VAR Check =
DIVIDE (
[Month of Engagement] ,
[Months In Contract L30]
)
RETURN
IF (
HASONEVALUE ( 'Tab'[ID] ),
IF ( Check >= 0.75 && Check <= 1.00, Check, 0 ),
CALCULATE (
SUMX (
CALCULATETABLE (
'Tab',
FILTER (
ALL ( 'Tab' ),
VAR __Check =
DIVIDE ( [Month of Engagement], [Months In Contract L30] )
RETURN
__Check >=0.75
&& __Check <=1.00
)
),
1
)
)
)
Here are the brief definitions
Month of Engagement:= CALCULATE(COUNTROWS(
SUMMARIZE('table','table'[MONTH_OF_ENGAGEMENT],"Count",DISTINCT('table'[MONTH_OF_ENGAGEMENT]))),'table'[FREQUENCY_FLAG]="Y")+0
Here MONTH_OF_ENGAGEMENT is value extracted from a date as YYYYMM
Months In Contract L30:=
Var DBRefreshDate30= [Database Refresh Date]-30
RETURN
DATEDIFF(DBRefreshDate30,[Database Refresh Date],MONTH)+1
Now basis on dividing Month of Engagement from Months In Contract L30, i am deriving a percentage, and checking if that percentage lies between 0.75 and 1.00
What I am trying to do is to take out from the table below, just the result from Madrid (70,89%) and Barcelona (83,92%) and consolidate both results weighting them according to "total production" measure.
The expected result would be the following = ( 70,89% x 52.550 + 83,92 x 135.100 ) / ( 52.550 + 135.100 ) = 80,27%
Here are the measures that I have created to build my matrix table
Total Production = sum(Database[Production])
Total Working Hours = sum(Database[Working Hours])
TotalExpectedProduction = sum(Database[Expected Production])
Avexpectedprod = divide(sumx(Database;[TotalExpectedProduction]*[Total Working Hours]);sum(Database[Working Hours]))
YTD Productivity =
CALCULATE (
DIVIDE (
SUMX (
SUMMARIZE (
Database;
Database[Matchine];
"AA"; [Total Production] / ( [Total Working Hours] * [Avexpectedprod] )
);
[AA] * [Total Working Hours]
);
[Total Working Hours];
0
);
DATESYTD ( Calendar[Date]; "30/06" );
FILTER (
ALL ( 'Calendar' );
'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
&& 'Calendar'[Fiscal Year] = MAX ( 'Calendar'[Fiscal Year] )
)
)
Here my data table structure
data table
Here the matrix table and the expected result
Image
Thank you so much for you Support
RBN
Done!!!
New2 =
DIVIDE (
CALCULATE (
SUMX ( VALUES ( Database[Location] ); [YTD Productivity] * [Total Production] );
Database[Location] = "Barcelona"
|| Database[Location] = "Madrid"
);
CALCULATE (
SUM ( Database[Production] );
Database[Location] = "Barcelona"
|| Database[Location] = "Madrid"
)
)
I have large amounts of raw fault data in Power BI.
code time status
x123 2019-04-22T23:57:00 ok
x123 2019-04-23T01:00:00 faulty
x123 2019-04-23T02:00:00 ok
x123 2019-04-23T23:00:00 faulty
x123 2019-04-24T01:00:00 ok
I need to transform this to show how long an item has been in a faulty state on a given day. So on the 23rd, the item was in a faulty state between 1 and 2a.m and then again between 11pm until past midnight.
code day % of day faulty
x123 23/04/2019 8.30% (2 hours)
Can I do this easily in Power BI or should I use another tool such as Azure Data Factory?
Add the following Calculated Columns to your table:
Report Date = Table1[time].[Date]
Fault Duration =
VAR CurrentTime = Table1[time]
VAR CurrentCode = Table1[code]
VAR PreviousTime =
CALCULATE (
MAX ( Table1[time] ),
FILTER (
Table1,
Table1[time] < CurrentTime &&
Table1[code] = CurrentCode
)
)
VAR NextTime =
CALCULATE (
MIN ( Table1[time] ),
FILTER (
Table1,
Table1[time] > CurrentTime &&
Table1[code] = CurrentCode
)
)
VAR FaultyFrom =
IF(
Table1[status] = "faulty",
Table1[time],
IF (
DAY(PreviousTime) = DAY(Table1[time]),
BLANK(),
Table1[time].[Date]
)
)
VAR FaultyTo =
IF (
Table1[status] = "ok",
Table1[time],
IF (
DAY(NextTime) = DAY(Table1[time]),
NextTime,
Table1[time].[Date] + 1
)
)
RETURN
IF(
ISBLANK ( PreviousTime ) || ISBLANK ( NextTime ) || ISBLANK ( FaultyFrom ),
BLANK(),
FaultyTo - FaultyFrom
)
Now create measures:
Faulty Hours = SUM ( Table1[Fault Duration] )
Faulty % Day =
IF (
HASONEVALUE ( Table1[Report Date] ),
DIVIDE (
[Faulty Hours],
DISTINCTCOUNT ( Table1[code] ),
BLANK()
),
BLANK()
)
Output:
See https://pwrbi.com/so_55825688/ for a worked example PBIX file