Categorize number of meetings PowerBI - count

So I created the following Measures:
First, I created this because I couldn't get VAR in the 2nd measure to pick it up from Table1.
Meetings in the Past 90 Days =
CALCULATE ( SUM ( table1[MEETING_HOSTED_PAST_90DAYS] ) )
Second, i created:
mtgs Category =
VAR mtgs = [Meetings in the Past 90 Days]
RETURN
SWITCH (
TRUE (),
mtgs = BLANK (), "0 Mtgs Past 90 Days",
mtgs >= 1 && mtgs <= 100, "1-100 Mtgs Past 90 Days",
mtgs >= 101 && mtgs <= 500, "101-500 Mtgs Past 90 Days",
"500+ Mtgs Past 90 Days"
)
but I also have another column called Account Manager. and when I filter on account manager it will not show me the just the filter but all the sites in the table below.

Related

Count of sick leave per day category

I have a PowerBI measure to calculate sick leave days between 2 dates.
CALCULATE(
COUNTROWS(PERIOD),
DatesBetween(
'Period'[Datekey],
min('Leave Management'[DateFrom]),
max('Leave Management'[DateTo])),
Filter(
Period,
'Period'[ISWorkDay] = 1 &&
'Period'[IsPublicHoliday] = FALSE
),
ALLSELECTED('Leave Management')
)```
a second measure(may not be essential) to categorize the leave days as
```DateDiff =
SWITCH(
True(),
'Staff Management'[workdays without holidays] <= 1 , 1,
'Staff Management'[workdays without holidays] = 2 , 2 ,
'Staff Management'[workdays without holidays] >= 3 , 3
)
table reference...[Table/Matrix][1]
I would like to count the number of Days per category, I have tried measures...
1DayLeave Distinct Count =
COUNTROWS(FILTER('Leave Management',[DateDiff]=1))
3DayCount =
COUNTX(Summarize(FILTER('Staff Management','Leave Management'[DateDiff] = 3
),"Leave 3 Day Catergory",'Leave Management'[DateDiff]),[DateDiff])
```[enter image description here][1]
[1]: https://i.stack.imgur.com/Wq9DV.png

Rolling 4 week average conversion rate, in R or Power BI

I am trying to create a rolling 4 week average conversion rate. The column LTA is the conversion rate and equals (Appts/Leads). Right now, LTA is week by week. I need to create a new column that is a 4 rolling conversion rate.
Here is the data.
Week Leads Appts LTA
4/17/2022 205 83 40.49%
4/24/2022 126 68 53.97%
5/1/2022 117 40 34.19%
5/8/2022 82 38 46.34%
5/15/2022 60 32 53.33%
5/22/2022 45 19 42.22%
5/29/2022 25 19 76.00%
So if we started at the bottom, the RollingAvg for May 29 would be (19+19+32+38)/(25+45+60+82) = 50.943 %
For the week may 22, the numbers would roll back one week, so it'd be (19+32+38+0)/(45+60+82+117) = 29.276 %
Help would be appreciated.
transform(data.frame(lapply(df, zoo::rollsum, k=4)), roll = Appts/Leeds * 100)
Leeds Appts roll
1 530 38 7.169811
2 385 70 18.181818
3 304 89 29.276316
4 212 108 50.943396
Simple solution for a calculated column in DAX:
RollingAvg =
VAR _currentDate = [Week]
VAR _minDate = _currentDate - 4*7
RETURN
CALCULATE (
DIVIDE (
SUM ( 'Table'[Appts] ) ,
SUM ( 'Table'[Leads] )
),
// Lift filters on table to have all rows visible
ALL ( 'Table' ) ,
// Add constraints to dates for a 4-week average
'Table'[Week] <= _currentDate ,
'Table'[Week] > _minDate
)
Or better yet, a measure that doesn't take up space in the data model:
RollingAvgMeasure =
/*
Calculates the 4-week rolling average if used with the Week dimension.
Else calculates the total rolling average.
*/
VAR _currentDate = MAX ( 'Table'[Week] )
VAR _minDate = _currentDate - 4*7
VAR _movingAvg =
CALCULATE (
DIVIDE (
SUM ( 'Table'[Appts] ) ,
SUM ( 'Table'[Leads] )
),
ALL ( 'Table' ) ,
'Table'[Week] <= _currentDate ,
'Table'[Week] > _minDate
)
VAR _total = DIVIDE ( SUM ( 'Table'[Appts] ) , SUM ( 'Table'[Leads] ) )
RETURN
// Replace if-statement with only return of _movingAvg to display the latest 4-week value.
IF (
ISFILTERED ( 'Table'[Week] ),
_movingAvg ,
_total
)

Teradata sql query - compare current day value with previous day value

I have 3 columns(CustomerId, Amount, ProcessDate) in a table (Customer).
Values are inserted daily in this table.
I want to get all the rows whose current day Amount is greater than previous day Amount.
CustomerId Amount Process_date
1 20 12/05/2021
2 30 12/05/2021
1 40 13/05/2021
2 25 13/05/2022
We have to print (1 40 13/05/2021) as 20 (previous day amount) is smaller than 40 (next day amount).
Query which I tried :-
select b.customerId, b.amount, b.process_date from customer a
join (select customerId, amount, process_date from customer where process_date = current_date ) as b
on
a.customerId = b.customerId and
a.process_date = current_date - 1 and a.amount < b.amount

How to calculate number of business days between 2 dates with Moment.js inclusive of start and end dates

https://www.npmjs.com/package/moment-business-days is super helpful but it doesn’t appear to be able to calculate inclusive difference between two dates.
In my example, I am trying to calculate PTO (paid time off) days.
So, if Friday, November 27th is a PTO day, then 2020-11-27 to 2020-11-27 should equal 1 day.
moment("2020-11-27").businessDiff("2020-11-27"); // => 0
I could add +1 but this will cause problems for other ranges.
For instance moment("2020-11-27").businessDiff("2020-11-27") + 1; // => 1 is now correct
But moment("2020-11-27").businessDiff("2020-11-29") + 1; // => 2, which is incorrect.
What I need is this…
2020-11-27 to 2020-11-27 equals 1 business day
2020-11-27 to 2020-11-28 also equals 1 business day because the 28th is a Saturday
Any suggestions?
You can do something like this
if(date1 === date2 && moment(date1).isBusinessDay()){
businessDay = 1;
}else {
businessDay = moment(date1).businessDiff(date2)
}

Using Case statement with multiple when in Teradata

Suppose I have a data table with the following fields:
CUSTOMER: either A or B
DAY: either Monday or Tuesday
PAID: either Y or N
The total number of rows being four, let's say the data table is this:
CUSTOMER DAY PAID
A Monday Y
A Tuesday N
B Monday Y
B Tuesday N
How do I create a SQL query on Teradata SQL Assistant, that will show the number of people who were Y on Monday and N on Tuesday? (or any of these combinations) I tried to use the query below, but cannot seem to figure out the logic. Your help is much appreciated!
SELECT DAY,
COUNT(CASE PAID WHEN 'Y' THEN CUSTOMER ELSE 0 END) AS PAID_CUSTOMERS,
COUNT(CASE WHEN PAID = 'Y' AND DAY = 'Monday' AND DAY = 'Tuesday' AND PAID = 'N' THEN CUSTOMER ELSE 0 END) AS CUSTOMERS_YM_NT
FROM T1
GROUP BY 1
ORDER BY 1
So, break each day down into a separate case statement:
case when DAY = 'Monday' and PAID = 'NO' then 'NO' else 'YES' end as Monday,
case when DAY = 'Tuesday' and PAID = 'NO' then 'NO' else 'YES end as Tuesday,
etc
Then, you can wrap that with another select and apply whatever criteria you want:
select
<whatever columns>
from
(select
case when DAY = 'Monday' and PAID = 'NO' then 'NO' else 'YES' end as Monday,
case when DAY = 'Tuesday' and PAID = 'NO' then 'NO' else 'YES end as Tuesday,
...
) t
where Monday 'YES'
and Tuesday = 'YES'

Resources