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
)
)
)
Related
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 )
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).
I want to implement a filter in a cubeset function to get the values only for a limited time period, e.g. 2 weeks. However, I struggle with the syntax of the filter function.
Getting the values in a cubevalue function works for the selected time period, but not in the cubeset function. Defining the cubeset function only by listing the time periods is also not an option, since it then gives you an additional column with the week nr, but what I need is to have the values in an aggregated form at the end.
The result of the cubeset will then be retrieved by a cuberankedmember function to have a ranking, and finally the cubevalue function delivers the values.
=CUBESET("Datamodel", "Filter( {[Contribution Flight].[Flt CarrierNo].&["&Overview!$B$17&"], [Allotment].[Allotment].&[n] , [Origin].[Origin Code].children} , {[Dep Date Itinerary].[Dep Date Itin Week].["&Overview!AN7&"],[Dep Date Itinerary].[Dep Date Itin Week].["&Overview!AM7&"]})")
The outcome should be the volumes by origin codes, for the above determined period of 2 weeks.
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.
WARNING - Using Excel 2011 for Macs, inexperienced user
Hi All,
I have a sheet in Excel with a bunch of categorical fields and some numerical ones as well. Let's say it looks like the following:
I would like to make a pivot table that will display the average click rate (avg_click_rate) of the unique combinations of [year, region], i.e. the combinations of fields in the pivottable's rows section.
For example, the avg_click_rate of [years=5] is:
(0.5*10)/(10 +5 ) + (0.6*5)/(10+5) = 0.53
while the avg_click_rate of [region=north] is:
(0.6*5)/(5+20) + (0.2*20)/(5+20) = 0.28
and the avg_click_rate of [years=5, region=south] is:
(0.5*10)/10 = 0.5
I know I have to make a custom Calculated Field to do this, but for the life of me I cannot figure out how to code the formula. Any help would be seriously, seriously appreciated.
To be clear, my formula would be:
SUM{ (click_rate * number_members) / SUM{number_members} }
where the numerator is a single value for each row included in the unique combination of [year, region], while the denominator is a constant - the total number_members for the unique combination of [year, region].
You should create a new column in your source table:
product = click_rate * number_members
And then create a Calculated Field in the pivot table:
CF = product / number_members
Using AVERAGEIFS:
AVERAGEIFS($C$2:$C$9,$A$2:$A$9,A2,$B$2:$B$9,B2)
EDIT:
You can add up to 127 conditions, see: AVERAGEIFS function
Criteria_range1, criteria_range2, … are 1 to 127 ranges in which
to evaluate the associated criteria.