Excel - MAX and MIN value by month for a certain item - excel

Can someone help me out with a formula?
I have a large database and I`m trying to figure out, how to get the MAX amount used in January 2017 for a product X.
I have found the averages using - AVERAGEIFS(Avg.de.time!E3:E80231;Avg.de.time!A3:A80231;C2;Avg.de.time!C3:C80231;">="&H7;Avg.de.time!C3:C80231;"<="&EOMONTH(H7;0))
Column A - Item no.
Column B - Supplier name
Column C - Order date
Column D - Receive date
Column E - Delivery time (D-C)
I`ve spent too many hours on trying to figure this out.
So I m asking for Help :)

Using array formulae you can rewrite your AVERAGEIFS statement using a conditional array expression as follows:
=AVERAGE(
IF(
(
(Avg.de.time!A3:A80231 = C2) *
(Avg.de.time!C3:C80231 >= H7) *
(Avg.de.time!C3:C80231 <= EOMONTH(H7,0))
) > 0,
Avg.de.time!E3:E80231
)
)
I've just formatted the code to make it easier to see where each of the criteria, criteria_ranges and value_range appear however this will obviously be one long line in your cell.
It's now very simple to swap out AVERAGE at the start with MAX, MIN or another aggregate function with the rest of the formula remaining identical.
=MAX(
IF(
(
(Avg.de.time!A3:A80231 = C2) *
(Avg.de.time!C3:C80231 >= H7) *
(Avg.de.time!C3:C80231 <= EOMONTH(H7,0))
) > 0,
Avg.de.time!E3:E80231
)
)
As this is an array formula, you will need to type it into your Excel cell and hit Ctrl-Enter to make it an array formula. You can check this worked as curly braces {} will appear around the formula.

Related

Calculation with respect to dates is incorrect in oracle

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 )

Incorrect result for nested condition in MEDIAN-IF excel

I have a following excel spreadsheet which consist of following fields:
Col A: Timestamp
Col B: Numerical result
Col C: Time duration taken for calculation of result
Now, I'm trying to find the median value of col C (Duration) for various month and year combinations.
e.g. For the month of march in 2019, what's the median value of duration?
I could've used the MEDIANIFS, but sadly it didn't exists. I'm trying the below thing also, but it's not giving the correct result(G1 is a drop-down which consists numerical valued years i.e. 2019, 2020 and so on)
MEDIAN(IF(YEAR(A3:A100) = G1, IF(MONTH(A3:A100) = 3, C3:C100)))
I also tried ANDing the conditions but it also didn't worked:
MEDIAN(IF((YEAR(A3:A100) = G1) * (MONTH(A3:A100) = 3), C3:C100))
If I put one condition inside the Median(If()), it's working fine. But, whenever I nest or concat conditions, it's not giving the correct result.
Any help/pointers will be highly appreciated.

Excel sumif function with conditions

I need to sum a column with alot of variables and i am having trouble when making it. ( see picture for reference)
I need to sum G (Sum time) if its less than 300 (<300), if B (Type) =1, if D (date) = input cell and if E( time) = a certain range that i can change, for example "7pm -12pm"
I don't have a ton of experaicen with having these conditions, this is what i have tried so far.
sumif(Table1[[ type]]=1, IF(Table1[[#All],[Date]]=K3, AND(Table1[[#All],[Time]]=K4, IF(Table1[[#All],[Sum Time (sec)]]=<300))))
Any help would be greatly appreciated
Picture here :
Try SUMIFS
=sumifs(table1[sum time (sec)],Table1[type],1, Table1[Date],K3, Table1[Time],K4, Table1[Sum Time (sec)],"<300")

How do i convert sumifs in excel to a PowerBI formula?

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

Power BI - I need a "countif" formula to look at unique entries in row/column

I have only been working in Power BI for a little over one week now, and now I have run into my first problem..
I need a way to do the same as in below Excel formula..
In Power Bi I have ONE table.
I want to count unique "Split Orders" in column "B"
But I only want to count them once..
So the first time it is found, it is counted as 1
Next I see it it is counted as 2 or 3 or 4 or more..
So formula says "if counted MORE than once, then return "X", else return "1"
And the IF statement then says if higher than 1, return 0 else return 1
I have many thousands of rows and I need to identify each as either unique or not..
But I can't seem to find the right combo of DAX formulas to do so.
I have looked at COUNTDISTINCT, CALCULATE, FILTERS, COUNTROWS, and many more.
They might be the right ones to use but I haven’t managed to find the right syntax.
Many of the DAX formulas I have tried, either return ONLY "1" or ONLY "0" or they return the total amount of unique orders..
Excel formula:
Row 2 = IF(B2="";0;IF(COUNTIF(B$1:$B2;B2)>1;0;1))
Row22 = IF(B22="";0;IF(COUNTIF(B$1:$B22;B22)>1;0;1))
Row32 = IF(B32="";0;IF(COUNTIF(B$1:$B32;B32)>1;0;1))
What you are looking for is a Calculated Column and not a Measure. Also you need to determine the order in which the [Split Order] column should be read.
You can do this by adding an index column in Power Query (Add Column tab). After doing that, add this Calculated Column:
IsFirstOccurence =
IF (
COUNTROWS (
FILTER (
'table',
'table'[Split Order] = EARLIER ( 'table'[Split Order] )
&& 'table'[Index] <= EARLIER ( 'table'[Index] )
)
) = 1,
1,
0
)
The result looks like this:

Resources