At first, let me tell you about the data I'm working with. It's web data from Google Analytics for the last 6-8 weeks so it's got I've got dates, values, and lots of dimensions. Here's what I'm trying to do with it in Power Bi.
I would like to compare the value sum for a specific period with the corresponding period. BUT! the normal parallel period formulas are not applicable in my case (or maybe I'm wrong and I can use those somehow) because I need the following logic in my comparison:
if less then or equal to the seven days are chosen in filters than compare with the vales seven days ago (so if two days are chosen compare to the two days week ago)
if more than seven days are chosen compare to the previous period of the same size (so if 13 days are chosen compare to the 13 days directly before)
Plus I would like this measure to be responsive to filtering on the dimension side.
I need a percentage difference but I m currently working on the measure that can at least return to me the value based on the logic above.
Here's what I've got so far (below). I've looked up this solution here and to be honest I understand only half of it.
The problem here is that when I'm trying to add all those dimensions (the bottom part of the solution) to be considered in this measure the calculation became super slow and not really usable.
I'm asking the community to help me optimize this script or maybe come up with the different solution to my problem.
Lots of thanks in advance!
Sessions Past Period =
CALCULATE(SUM (ci_dashboard_v7[Sessions]), FILTER ( ALL ( ci_dashboard_v7 ),
COUNTROWS (FILTER ( ci_dashboard_v7, EARLIER ( ci_dashboard_v7[Date] ) = DATEADD ( ci_dashboard_v7[Date],IF(DISTINCTCOUNT(ci_dashboard_v7[Date])<7,-7,DISTINCTCOUNT(ci_dashboard_v7[Date])), DAY )
&& ci_dashboard_v7[WMC_partner_lvl1]=EARLIER(ci_dashboard_v7[WMC_partner_lvl1])
&& ci_dashboard_v7[WMC_partner_lvl2]=EARLIER(ci_dashboard_v7[WMC_partner_lvl2])
&& ci_dashboard_v7[Campaign]=EARLIER(ci_dashboard_v7[Campaign])
&& ci_dashboard_v7[cd003]=EARLIER(ci_dashboard_v7[cd003])
&& ci_dashboard_v7[cd135]=EARLIER(ci_dashboard_v7[cd135])
&& ci_dashboard_v7[Channel]=EARLIER(ci_dashboard_v7[Channel])
&& ci_dashboard_v7[Channel_simple]=EARLIER(ci_dashboard_v7[Channel_simple])
&& ci_dashboard_v7[Date]=EARLIER(ci_dashboard_v7[Date])
&& ci_dashboard_v7[Country]=EARLIER(ci_dashboard_v7[Country])
&& ci_dashboard_v7[Domain]=EARLIER(ci_dashboard_v7[Domain])
&& ci_dashboard_v7[Week]=EARLIER(ci_dashboard_v7[Week])
&& ci_dashboard_v7[Week_day]=EARLIER(ci_dashboard_v7[Week_day])
&& ci_dashboard_v7[Year_current]=EARLIER(ci_dashboard_v7[Year_current])
&& ci_dashboard_v7[Week_current]=EARLIER(ci_dashboard_v7[Week_current])
&& ci_dashboard_v7[Week_before_current]=EARLIER(ci_dashboard_v7[Week_before_current])
&& ci_dashboard_v7[is_CRM]=EARLIER(ci_dashboard_v7[is_CRM])
&& ci_dashboard_v7[WMC_tm]=EARLIER(ci_dashboard_v7[WMC_tm])
&& ci_dashboard_v7[Platform]=EARLIER(ci_dashboard_v7[Platform])
&& ci_dashboard_v7[Device]=EARLIER(ci_dashboard_v7[Device])
&& ci_dashboard_v7[OS]=EARLIER(ci_dashboard_v7[OS])
&& ci_dashboard_v7[WMC_type]=EARLIER(ci_dashboard_v7[WMC_type])
&& ci_dashboard_v7[Source_Accengage_Pigeon]=EARLIER(ci_dashboard_v7[Source_Accengage_Pigeon])
&& ci_dashboard_v7[WMC_tool]=EARLIER(ci_dashboard_v7[WMC_tool])
&& ci_dashboard_v7[WMC_full]=EARLIER(ci_dashboard_v7[WMC_full])
&& ci_dashboard_v7[Source]=EARLIER(ci_dashboard_v7[Source])
))))
This solution assumes you only have dates (no times) in the ci_dashboard_v7[Date] column.
Here's what you can try:
Create a calendar table and call it Date. The easiest way to do this is to create a calculated table with the following formula: Date = CALENDARAUTO()
Create a one-to-many relationship between 'Date'[Date] and ci_dashboard_v7[Date]
Hide the ci_dashboard_v7[Date] column and only use 'Date'[Date] in slicers
Create the following measure:
Sessions Past Period =
CALCULATE (
SUM ( ci_dashboard_v7[Sessions] ),
DATEADD ( 'Date'[Date], - MAX ( 7, COUNTROWS ( 'Date' ) ), DAY )
)
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).
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 have two important details that are inputted into an excel table, Job_Start_Date and Job_Hours (meaning the hours required to complete the job). Given certain working hours (eg 7:00am-3:30pm) I need to calculate what day and what time they will finish. I already have that basic bit working, but I cannot for the life of me figure out how to skip weekends in that calculation (Note that there is a boolean for Sat/Sun that defines whether that day should be skipped).
Here is an example of the data
and an example of the data visualization: (The DIV errors are because employee count equals 0, pay this no mind.)
.
This is the formula used in the visualizer (a massive index match)
=IFNA(INDEX(INDIRECT(Allocation!$A$1), MATCH(1,($A3 = INDIRECT(Allocation!$K$1))
* (C$1 >= INDIRECT(Allocation!$C$1)) * (C$1 <= INDIRECT(Allocation!$D$1))
* IF(C$1 = INDIRECT(Allocation!$C$1), ($B3 >= INDIRECT(Allocation!$E$1)),
($B3 >= INDIRECT(Allocation!$I$1))) * IF(C$1 = INDIRECT(Allocation!$D$1),
($B3 < INDIRECT(Allocation!$F$1)), ($B3 < INDIRECT(Allocation!$J$1))), 0)),"")
As you can see in the image, Saturdays need to be skipped (being FALSE), but it is still shown on the visualizer. However, if I include a statement that matches the Saturday condition (so it only shows up on a Saturday if TRUE), it will not alter the end date and thus will not push the final day to Monday.
Essentially the question is: How can I skip days but preserve the 'working hours'. This must be done in excel formulas in the same Job table (first image).
Thanks.
Here is how I got it working using WORKDAY.INTL.
First is a nested IF to determine which weekend type to use for the workday.intl function
Weekend=IF(OR([#[JOB SATURDAY]], [#[JOB SUNDAY]]), IF(AND([#[JOB SATURDAY]], [#[JOB SUNDAY]]), -1, IF([#[JOB SATURDAY]], 11, 17)), 1)
Then a second if statement that references that value and then spits out the correct date
=IF([#[Weekend]] = -1, [#[JOB START DATE]]+[#[Working Days]], WORKDAY.INTL([#[JOB START DATE]], [#[Working Days]], [#[Weekend]]))