Please Help.
My table (TestTable) has the following columns - Individual / Date / Pct. Achieved.
I am trying to use the LASTDATE function to work out when an individual last achieved 90% or above.
My forumla thus far is as follows;
=CALCULATE(LASTDATE(TestTable[Date]),FILTER('TestTable',[Pct. Achieved]>0.895))
This works but only shows when the last individual achieved >90% and uses that date for everyone else. However, I would like it to look at each individual separately and return a date for when that individual last achieved >90%.
Thanks in advance.
If you want it split by individual, then you'll need to add the individual to your filter:
CALCULATE (
LASTDATE ( TestTable[Date] ),
FILTER (
TestTable,
TestTable[Pct. Achieved] > 0.895 &&
TestTable[Individual] = EARLIER ( TestTable[Individual] )
)
)
Note: EARLIER has nothing to do with dates but rather refers to the earlier row context (rather than the row context within FILTER).
Related
I am trying to count data in a range named 'democracy' based on a date start and date end. I have attempted to get this done, but can't seem to fit the pieces together
Component 1
In the SumIf I have:
{=SUM(IF((democracy_highlighted=1)+(democracy_shown=1),1,0))}
The named range democracy contains 2 columns, "highlighted" and "shown", this works in checking both the columns for the value of 1 to be present in one of them.
Component 2
In the countif I have:
=COUNTIFS(democracy_shown,1,DateList,">="&$B$3, DateList,"<="&$B$4)
=COUNTIFS(democracy_highlighted,1,DateList,">="&$B$3, DateList,"<="&$B$4)
This shows data between the start and end dates.
What I need to do is use the {=SUM(IF ...)} component, and limit the results based on start date and end date values?
You could use SUMPRODUCT - something like:
=SUMPRODUCT(SIGN(((democracy_highlighted=1)+(democracy_shown=1)))*(DateList>=$B$3)*( DateList<=$B$4))
I have to calculate some forumales based on Dates coming from table. For reference the exact value with formula is provided in Excel.
The formula and Excel answer is below.
Formula in Excel :
=IF(
D12>=DATE(2016,10,1),
(S12-T12)+(S12-T12)*2.5%
+(
IF(
ROUNDDOWN(YEARFRAC(DATE(2016,4,1),D12),0)=0,
0,
EFFECT(
(ROUNDDOWN(YEARFRAC(DATE(2016,4,1),D12),0)*2.5)%,
ROUNDDOWN(YEARFRAC(DATE(2016,4,1),D12),0)
)
)
)
*
((S12-T12)+((S12-T12)*2.5%)),
((S12-T12))
)
-(
IF(
AND(
D12>=DATE(2018,4,1),
D12<=DATE(2018,12,21),
E12<=DATE(2018,12,21)
),
7.69%*(S12-T12),
0
)
)
And the answer for which calculation in Excel is:- 30,153
and my answer coming is 28700/-
The value for D12 = 03/05/18 (dd/mm/yy) format, E12 = 21/04/19
S12 = 30000, T12 = 2000,
Here is my calculation logic provided in oracle.
IF TO_DATE(V_FINALSRDATE, 'dd-mm-yy') >= TO_DATE('01-10-2016', 'dd-mm-yy')
THEN
v_STD_REVISED_AMT := (V_STANDRD_AMT - v_OD_Discount) + (V_STANDRD_AMT - v_OD_Discount) * 2.5/ 100;
dbms_output.put_line( 'Standard revised amount 1: ' || v_STD_REVISED_AMT);
ELSE
v_STD_REVISED_AMT := (V_STANDRD_AMT - v_OD_Discount);
dbms_output.put_line( 'Standard revised amount 2: ' || v_STD_REVISED_AMT);
END IF;
Do I need to add one more IFELS part? Where is my logic failing?
Please help as where my logic is failing.
You are not doing the full calculation; you have calculated the (S12-T12)+(S12-T12)*2.5% but you have missed the second part of the calculation.
You need to implement an Oracle version of the YEARFRAC function using US (NASD) 30/360 day count basis (since you are not passing a 3rd argument to YEARFRAC) and then add in the second half of your Excel formula into your PL/SQL calculation.
If you want it to have the same behaviour as Excel then you will also need to implement all the bugs that Excel has as the documentation notes that:
The YEARFRAC function may return an incorrect result when using the US (NASD) 30/360 basis, and the start_date is the last day in February.
However, since the exact nature of the bug is not detailed, you will need to work out what the errors are and implement them yourself. But since you are using a start_date of 2016-04-01 then this may not apply (unless you also need to generalise this function for use elsewhere).
Alternatively, since you appear to be rounding the year fraction down to the nearest whole number then you are only calculating the number of full years between the dates and, instead of YEARFRAC, you could use:
EXTRACT( YEAR FROM (V_FINALSRDATE - DATE '2016-04-01') YEAR TO MONTH)
Or
FLOOR( MONTHS_BETWEEN( V_FINALSRDATE, DATE '2016-04-01' ) / 12 )
Fairly new and self-taught with DAX. I run an accuracy log that tracks incoming applications (Application[Application_ID]) and errors committed in processing that application (Error_Log[Application_ID]).
I want to find the number of applications that contain more than one error. For example, if 10 applications have errors, 6 of those applications have 1 error and the rest have 2 or more errors, I want to return the value of 4.
I'm trying to avoid a calculated column (like a "Multiple_Errors" TRUE/FALSE column) as it's refresh times are already longer than I'd like, but if it's unavoidable, it could be accommodated.
We were able to build an Excel formula with SUMPRODUCT for a very high level summary of the information, but I want more granularity than that formula can give me.
The online search has only led to finding articles on how to count the number of duplicates, flag the duplicates, remove duplicates or some other task, where I need to count a distinct number of values that have been duplicated within a table.
I have tried a few different DAX measures, but all of them have yielded incorrect results. For example...
=
CALCULATE (
DISTINCTCOUNT ( Error_Log[Appplication_ID] ),
FILTER ( Error_Log, COUNTA ( Error_Log[Appplication_ID] ) > 1 )
)
Drilling down into this result shows that all of the applications with errors are being pulled over, rather than only those with greater than one error.
After playing with a few options, I haven't been able to find the solution. Any help/pointers/direction would be greatly appreciated!
I think you are looking for something like this:
Measure =
COUNTROWS (
FILTER (
SUMMARIZE (
Error_Log,
Error_Log[Application_ID],
"count", COUNTROWS ( Error_Log )
),
[count] > 1
)
)
The SUMMARIZE function returns a virtual summarized table, with the count of each Application_ID in a column called "count". The outer COUNTROWS function then returns the number of rows in the virtual table where [count] is greater then 1.
Your measure is fine and works as defined. Please see the attached screen.
App ID 100 has 4 Type 1 errors, 101 has 2 Type 2 and 1 Type 3 errors but because of the distinct count, they have 1 each.
102 has single Type 3 but we are using Error Type to group the log, Type 3 show two counts (1 each for 102 and 101)
Note that COUNTA ( Error_Log[Appplication_ID] ) > 1 condition has been satisfied for 102 also because of grouping column.
We do not see Type 6 in the pivot table at the right because of COUNTA ( Error_Log[Appplication_ID] ) > 1.
So, although the measure works, we might miss interpreting the result or we might miss to use correct DAX for the requirement.
I am trying to replicate the following excel formula in PowerBi. It adds all the refunded costs from a Unique identifier between a date period
I have tried using the Sumx function in powerBi but It doesn't return the values i need it to return.
SUMIFS([#Refunded;
[#Date];">="&MAX([#Date])-42;
[#Date];"<="&MAX([#Date])-14;
[#UID];)
It needs to return the sum of the same unique identifiers between 42 and 14 days earlier.
I have tried solving is as follows:
calculate(SUM([Refunded]),DATESBETWEEN(all_funnel_data_view[Date].[Date],Value(all_funnel_data_view[Date].[Date])=TODAY()-42,Value(all_funnel_data_view[Date].[Date])=TODAY()-14))
But is only returns empty field
Use the FILTER function as the second argument of CALCULATE. In this, you can filter the date column of the all_funnel_data_view table for a date in the specified time frame. I'm assuming that Refunded is a column, not already a measure. If so, qualifying it with the name of the table will help to make the measure easier to read. In the following example, "YourFactTable" is used for this.
CALCULATE
(
SUM(YourFactTable[Refunded]),
FILTER(all_funnel_data_view,
AND
(
all_funnel_data_view[date] >= TODAY() - 42,
all_funnel_data_view[date] <= TODAY() - 14
)
)
)
I need to calculate the total shipping cost for some sales orders. The dataset is as follows:
The issue I have is that although the shipping cost should be taken into account only once per order in the calculation, in the dataset it is repeated for each order item, thus a simple duplicates shipping costs:
=SUM(MyTable[Shipping]) = 90 // wrong value
However what I need is to:
filter the table to only keep 1 line for each order
sum up the shipping
Which should be something like:
=SUMX(FILTER(MyTable,<filter>),MyTable[Shipping]) = 35 // correct value
But I'm struggling to write the <filter>. I found DISTINCT which returns the list of unique order IDs, but not their corresponding row.
Does anybody have any ideas how I could write the filter to calculate shipping properly?
The X functions are non intuitive but very powerful - you are on the right lines.
I would approach this with two measures, the first to sum the shipping cost and divide it by the number of rows for that order. (Key to the second half is the ALL() which opens up the context on the column referenced whilst retaining the other contexts.)
And the second to iterate that measure by order and sum the outcomes.
[Allocated Shipping] =
SUM ( MyTable[Shipping] )
/ CALCULATE ( COUNTROWS ( MyTable ), ALL ( MyTable[Item] ) )
[Iterated Shipping] =
SUMX(VALUES(MyTable[Order]), [Allocated Shipping])
The simplest approach would be to use a Helper column. In E2 enter:
=IF(COUNTIF($A$1:A2,A2)>1,0,1)
and copy down. This will identify the unique values in column A. To sum these unique values, use:
=SUMPRODUCT(--(E2:E9=1)*(D2:D9))
For your data:
The value is 35
Naturally if the data were filtered you would use a variation of the SUBTOTAL() function or an additional helper column.
In a very similar way to Gary's recommendation, you could use (in an additional col - E2):
=IF(COUNTIF($A$2:A2,A2)>1,D2,0)
This will show the cost of the delivery in col E itself. You can then just SUM(E2:E) to see the total cost (35).