I am new to Power BI and have the following issue:
I tried to build a formula for a frequency counter. I got some examples from the web and I was able to build this working formula. The basic idea behind is to categorize an item with the values: daily, weekly or first time.
I tried to add an IF-Statement to the formula, that is checking a calculated column "Time frame", which shows the duration of an item in minutes.
Basically it should run this formula only if the Column "Time frame" is equal or bigger 1.
Now the formula gives to items with a Time frame of 0, the value first time. But they should be ignored or blanked.
Calculated column =
Var freqcount =
COUNTAX(FILTER(ALL('Count'),
AND([Date]>=DATEADD('Count'[Date],-6,DAY)&&[Date]<=EARLIER([Date]),[ID]=EARLIER('Count'[ID]))),ID])
return
if(freqcount>=4,"Daily",if(freqcount>=2,"Weekly",if(freqcount>=1,"First time","Inactive")))
I would be thankful, if someone could support me with this issue.
Edit: an ID can occur multiple times in my table but with different dates. But only once with the same date. For example:
ID 1, Date 01.01.2020
ID 1, Date 02.01.2020
ID 1, Date 03.01.2020
it is easier to use calculate:
Calculated column =
var rDate = yourTable[Date]
var rID = yourTable[ID]
var freqCount = CALCULATE(yourTable('Count'), FILTER(yourTable, rDate >= DATEADD(yourTable[Date], -6 , DAY) && rID = yourTable[ID] && yourTable['Time frame'] > 0))
return if(freqcount>=4,"Daily",if(freqcount>=2,"Weekly",if(freqcount>=1,"First time","Inactive")))
you see how I simply added the Time frame to the expression. Also I removed the use of earlier by using var's so it is better readable.
Related
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.
I have a project where I need to break people into 3 buckets with task lists that rotate quarterly (Phase A = task list 1, B = task list 2, C = task list 3). The goal here is to sort people into the buckets based on a departure date, with the ideal being that they would depart when they're in the C phase. I have a formula already set up that will tell me the number of quarters between the project start date and the person's departure date, so now I'm trying to figure out how to get Excel to tell me if a person's departure date falls within their bucket's C Phase.
I have this formula in a column called DEROSQtr:=ROUNDDOWN(DAYS360("1-Oct-2020",[#DEROS],FALSE)/90,0)
Now the easy way to approach this would be to build a static array and just see if that formula results in a value in the right array, where the numbers in the array define which quarter from Oct 2020 that the bucket's C Phase is going to be in:
ArrayA = {1;4;7;10;13;16} ArrayB = {2;5;8;11;14;17} ArrayC = {0;3;6;9;12;15}
The formula that pulls this all together is then:
=IF([#EFP]="A",IF(IFNA(MATCH([#DEROSQtr],ArrayA,0),-1)<>-1,TRUE,FALSE),IF([#EFP]="B",IF(IFNA(MATCH([#DEROSQtr],ArrayB,0),-1)<>-1,TRUE,FALSE),IF([#EFP]="C",IF(IFNA(MATCH([#DEROSQtr],ArrayC,0),-1)<>-1,TRUE,FALSE),"-")))
Now while this will work for as long as I build out the static array, I'm trying to figure out how to define each of these buckets with a formula that Excel can work with, i.e. bucket A hits phase C in 3n + 1 quarters where n is the number of cycles through all 3 phases, so ArrayA = 3n+1, ArrayB = 3n+2 and ArrayC = 3n. What I'm hunting for here is the best way to define each of the arrays as a formula.
After some additional digging and looking back at how to define each array, I came across the MOD() function in Excel. I was then able to rewrite the formula that does the checking as =IF([#EFP]="A",IF(MOD([#DEROSQtr]-1,3)=0,TRUE,FALSE),IF([#EFP]="B",IF(MOD([#DEROSQtr]-2,3)=0,TRUE,FALSE),IF([#EFP]="C",IF(MOD([#DEROSQtr],3)=0,TRUE,FALSE),"-"))), replacing ArrayA(3n+1) with MOD([#DEROSQtr]-1,3), ArrayB(3n+2) with MOD([#DEROSQtr]-2,3), and ArrayC(3n) with MOD([#DEROSQtr],3).
Since I do not have the data you are calculating your quarter, its difficult to give you exact answer. However, as I understand your have a column which has the formula to calculate the quarter say "Formula_Col"
Solution will be to add a new column and flag it based on the values in "Formula_Col".
If you can give some sample data I can provide exact answer.
I managed to get in Excel desired % of time difference from column E, easy job just changed the Data Type to Percentage. What are we calculating is % of these TimeDifferences, one per one (other columns inconsiderable).
The same thing isn't in PowerBI, where I am not able to calculate it properly, always getting "1" before comma and then the result - you can compare it in both tables/columns what I am talking about.
I am looking for the way/DAX/measure how to properly calculate it, no matter in decimals or directly to percentage, as long as the % is the same as in Excel column. Any ideas?
P.S Left is Excel and right is PowerBI!
Seems Excel is basing the percentage on 24 hours, this I used in the calculation (24 hours = 24 * 3600 seconds).
I started combining in power query the date and the time, this has to do with the fact that you go over the day and your calculation still needs to be correct.
Go to query editor. select both columns, combine them. Next change the type to Date/Time, result:
Save and close editor.
In Power Bi, add a column:
NextDate = LOOKUPVALUE(Explog[Date];Explog[Index];Explog[Index] + 1)
This is picking up the next Date based on Index + 1
Add another column TimeDiffSec, calculating the datediff in seconds:
TimeDiffSec = DATEDIFF(Explog[Date];Explog[NextDate];SECOND)
Last step is adding a column for percentage:
% of time difference =
var perc = Explog[TimeDiffSec]/ (24*3600)
return if(perc >= 1; perc - 1; perc)
End result:
Note: If you have a situation you do not want to mix the System (STYRAX - scrubber) you can use the following for the NextDate:
NextDate =
var nextIndex =
CALCULATE(MIN(Explog[Index]);
FILTER(Explog;Explog[Index] > EARLIER(Explog[Index]) && Explog[System] = EARLIER(Explog[System])))
return
LOOKUPVALUE(Explog[Date];Explog[Index];nextIndex; Explog[System];Explog[System])
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:
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]]))