Apply a custom formula to only the visible cells after filtering - filter

I want to apply the following formula to only filtered cells. I'm tracking attendance % and want to just see it by week and month when I filter.
=IFERROR((COUNTIF('Individual Absenteeism (Draft)'!$C$2:$C$225,"A")+(COUNTIF('Individual Absenteeism (Draft)'!$C$2:$C$225,"L")))/(COUNTIF('Individual Absenteeism (Draft)'!$C$2:$C$225,"P")+(COUNTIF('Individual Absenteeism (Draft)'!$C$2:$C$225,"A"))+(COUNTIF('Individual Absenteeism (Draft)'!$C$2:$C$225,"L"))),"")
I built the formulas to measure attendance percentages from a spreadsheet that uses a "P" for present, "A" for absent and "L" for planned absence.
I was hoping to be able to filter the table or range by date (months and weeks) and have the formula update.

Related

SUMIFS Between Conditions

I am looking for some help with a SUMIFS formula.
I am trying calculate the revenue between dates for a coupon code, where the coupon code sales are in a separate sheet. I need the between dates to be until that discount code appears in the sheet again.
For example,
If a discount code is promoted on the 25th of January and again on the 30th of January, I need the 25th of January row to show the sales since then until the SAME code is promoted again (eg. between 25th January and between 30th January). The 30th of January row would then show the revenue from that date onwards, until the code appears again in another date row in the future.
This is my formula:
=SUMIFS('Code Revenue Feed'!$E:$E,'Code Revenue Feed'!$C:$C,D2,'Code Revenue Feed'!$A:$A,">=" &$B2)
This formula does not show between dates, only from the date it is promoted but I need to show from that date, until the next date the code appears again.
Here's my dataset (please filter the code column by KATIEHAYES so you can see what I mean):
https://docs.google.com/spreadsheets/d/1kzU6T6a95WPoCDkkMjDmqWkKTDOxA0whn1Zk5kGRbBQ/edit?usp=sharing
For this to work, you need to enter an end date in column C (in my copy of your data, this is in cell C664 of the Posting Details UK sheet) where I have chosen 31-Dec-2022 (as your file is view-only, and because you appear to have a filter active on the Posting Details UK sheet, when I copied your data the last row of data on my sheet is 663)
=SUMIFS('Code Revenue Feed'!$E$3:$E$5180,'Code Revenue Feed'!$C$3:$C$5180,D2,'Code Revenue Feed'!$A$3:$A$5180,">="&C2,'Code Revenue Feed'!$A$3:$A$5180,"<"&INDIRECT("C"&IFNA(match(D2,D3:D$663,0)+ROW(),664)))
the above formula can be entered in cell E2 of your UK sheet, and then copied down. This formula uses the INDIRECT() function to determine the 'until' date - if a match for the current coupon code cannot be found in the remaining rows, then the end date from row 664 is used (you will have to adjust both the 663 and 664 references as you have almost 200 more rows of data).

Amazon Quicksight - Dynamic filter latest week by default

I think the question is fairly simple. I would like to have a dynamic filter on Quicksight. I have the column week which is a number (3, 4, 5 and 6) for example. The data is refreshed every week.
We want to show only the latest week by default (out of weeks 3, 4, 5 and 6, I want to filter by default on 6), but then the users can select if they want to see more weeks.
The week after, the default filter would be 7, and so on.
Is there a way to tell the filter to automatically filter by rule of MAX(week) or something like that?
It would be very helpful. I have other alternatives but they are not that great.
I would choose a date field that I understand that must exist in your data and then create a dynamic filter on that date field.
You create filters on date fields by selecting the filter conditions and date values that you want to use. There are three filter types for dates:
For your case, you will have to use
Relative – A series of date/time elements based on the current date. You can filter records based on the current date and your selected unit of measure (UOM). Date filter units include years, quarters, months, weeks, days, hours, and minutes.
Use the following procedure to create a relative filter for a date field.
On the toolbar at the left, choose Filter.
In the Filters pane that opens at left, choose the plus icon (+), and then choose a date field to filter on.
A new filter is added to the Filters pane.
In the Filters pane, choose the new filter to expand it.
For Filter type, choose Relative dates.
Choose a unit of time (week for your case).
Choose how you want the filter to relate to the time frame. For example, if you choose to report on weeks, your options are previous week, this week, week to date, last N weeks, and next N weeks.
If you choose Last n UOM, specify a number for your range—for example, last 2 weeks, or last 1 week.
Second solution.
Add Filter
Choose week
Type Top and Bottom Filter
Show Top write 1
By week ( use max aggregation)
Pasting an image from an analysis that I do the same thing for integer column year

Google sheets Countif function with UTC timestamp

I am trying to count number of IDs that exist as of a particular date (see Summary tab). However, since the dates (column A) in raw data tab are in UTC timestamp format, the formula returns 0.
My formula is countif('raw data'!A:A,"<="&A2)
How do I adjust the formula to convert UTC timestamps to datevalue within countif function.
I also would like to make this countif function work with arrayformula so that I don't have apply the formula on each row.
Here is the sample sheet :
https://docs.google.com/spreadsheets/d/1IFAAiguhKD0xK8SYsnzMBSar4IFAQPzZfIh0U44bZWI/edit?usp=sharing
Translate first your dates by
=arrayformula(if(A2:A="",,VALUE(left(A2:A,10))))
You can use
=sumproduct(('raw data'!D:D<=A2)*('raw data'!D:D<>""))
Now, if you want arrayformula to be applied, first make a query
=QUERY('raw data'!A:D,"select D,count(B) group by D")
then compute a total as following
={"Total ID";ArrayFormula(if(isblank(G2:G),,mmult(1*(transpose(row(G2:G))<=row(G2:G)),1*G2:G)))}
both formulas are on yellow cells

Power Query - DATEADD fails once current year filter applies

Please help. I don't understand why I have 2 similar data models and one works but the other does not.
I have a fact table with a Calendar Key and data as granular by day by location. I have a calendar dimension table with a Calendar key, each individual date, and month/fiscal year definitions.
Measures are Rev = SUM(FactTable[RevColumn]) then Rev PY = CALCULATE([Rev], DATEADD(CalendarTable[Day_Date], -1, YEAR))
Model 1 in Power BI, when I apply date filters, Rev calculates the total revenue & Rev PY calculates last year's rev for same range. Even if I select all dates that are YTD (which is tedious)
Model 2 in Excel 2016 Power Query, when I apply a year filter, Rev calculates total revenue for YTD in Fiscal Year & Rev PY is blank.
I don't understand what is different and why it would even fail in the first place. Calculate is supposed to override the filter context of the current filters right?
Also: the only "Date" type columns are located in the calendar table so it's not possible for me to select the wrong table.
I ultimately had to ask a professor on Udemy.com. The solution is to mark you calendar dimension table as a "Date Table." Since I'm combining the 2 tables on a whole number field, the time intelligence functions only work when filtering with date columns.
By marking the Calendar table as the Date table, the time intelligence functions know to use any attributes from that table to filter down the date ranges and get and display the appropriate answer.
In Power Pivot view, click the "Design" ribbon, then click the "Date Table" button and the "Set Default" button after that.
This resolved all issues I had.

Rank only for latest month

I've a calculated field "Total Revenue" which blends revenue from multiple data sources in Tableau.
Based on this field (aggregate field) on monthly basis, I would like to show only TOP 5 items with highest revenue as of latest month.
As shown in above table, items have to be filtered out (as they are TOP 5 in March) based on revenue data as of the latest month (March). How can this be achieved using RANK()? I'm not able to rank only for latest month as formulated below because it shows error as I cannot mix aggregate and non-aggregate functions.
IF DATETRUNC('month'),ReportDate)=//March 1st date given//
THEN RANK(Total Revenue)
END
My solution is a kind of workaround but seems to be working:
Create a calculated field with below formula:
IF DATEPART('month', {MAX([date])}) = DATEPART('month', [date])
and DATEPART('year', {MAX([date])}) = DATEPART('year', [date])
THEN
[revenue]
ELSE
0
END
The {MAX([date])} part on the code gets the maximum date in your data, it is fixed with { and } characters so that the value is not effected by the filters, date partitions etc. If you want the sorting month to be the one we are in then you should change that part with NOW()
Now we have a value containing only the sum of the latest month and we can sort our visual with this Measure.
You can drag your new measure (I called my measure: 'last month revenue') to the details and right click your item pill on the Rows, sort it by your new field.
And finally drag your item to the filters and go to Top tab, make filter your data according to sum of "last month revenue" measure.
Below screenshot shows the excel data and the final Tableau table:

Resources