Initially I set up a query based on a search by month and year in a single dropdown using this formula
=QUERY(Haulage!A2:R, "SELECT * WHERE 1=1 "&IF(A2="All Months",""," AND LOWER(M) = LOWER('"&A2&"')"), 1)
This works great but I have now adapted my dropdowns to become a dependent dropdown with the first dropdown being by year which then filters the 2nd dropdown by that year. In the second dropdown I want to include an "All 2022" option which will then filter my query by everything with 2022 in the date.
I am struggling to adapt my formula to be able to make this work though so would appreciate any help
Edit:
Link to a test variant of the spreadsheet - https://docs.google.com/spreadsheets/d/1AewSFMxQjnYD44rkPk6h7TGlio2bwm8hv_mAkGiaEwA/edit?usp=sharing
Note that the dependent dropdowns are the wrong way around at the moment - so the J1 dropdown triggers the A1 dropdown and then the selection in A1 transfers to the "Date Filter" sheet
Edit - 30/05/22:
Looking to build on and adapt the above to include a filter by specific date as well via a 3rd dependent dropdown.
It's in the initial stage in my head but my initial wondering is whether the filter can be applied using 3 different dropdowns. So I would have dropdown1 for YEAR, dropdown2 as MONTH & YEAR and then dropdown3 as DATE each dependent on the previous one.
Would it be possible to filter by year when dropdown1 is selected, then by month if a selection is made in dropdown2 and then by specific date if a selection is made in dropdown3 - ie I select 2022 in dropdown1 and all 2022 records are filtered, I then select May 2022 in dropdown2 and this changes the filter to records from May 2022 and then I select 2nd May 2022 from dropdown3 and that filters down to records from that date only?
Try
=QUERY(Haulage!A2:R, "SELECT * WHERE " & if(A2="All","A is not null",if(left(A2,3)="All","(M) LIKE ('%"&SUBSTITUTE(A2,"All","")&"')","LOWER(M) = LOWER('"&A2&"') ")) , 1)
the sentence is if(A2="All","A is not null",if(left(A2,3)="All","(M) LIKE ('%"&SUBSTITUTE(A2,"All","")&"')","LOWER(M) = LOWER('"&A2&"') ")) it means that
if A2 is All, all rows will be selected when A is not null
if A2 starts with All, we will keep all rows containing A2 without All (like %yyyy),
and if A2 does not start with All, we will keep rows with an exact value than A2
edit
if you encounter mixed values (numeric and string), apply to_text and change A to Col1, B to Col2 etc. as follows
=QUERY(arrayformula(to_text(Haulage!A2:R)), "SELECT * WHERE " & if(A2="All","Col1 is not null",if(left(A2,3)="All","Col13 LIKE ('%"&SUBSTITUTE(A2,"All","")&"')","LOWER(Col13) = LOWER('"&A2&"') ")) , 1)
Related
I have a Google Sheet that has a cell that I want to use as a drop-down filter for another range within the sheet.
You can take a look at the sheet HERE.
Cell G11 is the cell that I wish to have the drop-down filter in.
Range B15:H69 is the range that should be filtered upon using this filter.
So, for example - if I select 'Barbarian' in the G11 drop-down the sheet should go from something like this (cut short for size of post sake):
To something like this:
I've tried using Named Ranges, using a seperate sheet to filter the data, and a couple other methods I found. Nothing seems to work exactly how I want it to, like in picture #2.
try:
=INDEX(LAMBDA(x, SPLIT(FLATTEN(SPLIT(FLATTEN(QUERY(TRANSPOSE(x),,9^9))&"×", "×")), " "))
(QUERY({ROW(Data!A2:D), SORT(Data!A2:D, 3, 0)},
"select Col1,Col2,'♀',Col3,Col4,'♂',Col5 where Col3 = '"&G11&"' label'♀''','♂'''")))
UPDATE:
=INDEX(LAMBDA(x, SPLIT(FLATTEN(SPLIT(FLATTEN(QUERY(TRANSPOSE(x),,9^9))&"×", "×")), " "))
(QUERY({ROW(Data!A2:D)-1, SORT(Data!A2:D, 3, 0)},
"select Col1,Col2,'♀',Col3,Col4,'♂',Col5 where 2=2 "&IF(
REGEXMATCH(G11, "(?i)all|n\/a|^$"),," and Col3 = '"&G11&"'")&" label'♀''','♂'''")))
I've been working on a spreadsheet with over 100 rows, and found a hacky way to incorporate a "hide" checkbox that will hide any row where column C matches a specific value (building type), specified beside the box. To do this, I first created a function like this: =FILTER(Data!A1, OR(Data!$C1<>$O$2, $P$2)) and dragged that across every row and column in a seperate sheet. This reads as, "Display current cell if the corresponding column C in that row in Data does not match the building type, or if the the checkbox is checked. This way, the whole row is hidden when the building type matches, and the box is unchecked. A1 adjusted to each row individually, $C1 referenced the building's type, $O$2 referenced the targeted type to potentially hide, and $P$2 was the checkbox.
Problem #1: This created a lot of formulas in hundreds of cells, and when the building type was not found, it displayed #N/A across the entire row. A Filter View was able to hide these values, but it was inconvenient to have to reset the values every time I wanted to hide or unhide another building type.
My Attempt to Fix: I used a filter function once again to recreate the entire sheet from one cell, hiding the appropriate rows, using this: =FILTER(Data!A2:J191, ARRAYFORMULA((Data!$C2:C191<>$O$2)+(Data!D2:D191*$P$2)) This is the hacky part. I multiplied the checkbox's "true" by an array arbitrary positive numerical values in the D column to "OR" it with each building type value to achieve the same goal as before, but for EVERY cell.
Problem #2 arose: When I get my beautiful sheet, I can not sort it via a filter view, or it will throw an error and display nothing. I'm resorting to sorting the original tab, but intend to have it be ignored entirely. So how do I combine these two, Filter View, and Filter Function, to create a nice spreadsheet where I can SORT AND HIDE rows?
Bonus Problem #3: To add more buttons, my formula is this: =FILTER(Data!A1:J191, ARRAYFORMULA((Data!$C1:C191<>$O$2)+(Data!D2:D192*$P$2)), ARRAYFORMULA((Data!$C1:C191<>$O$3)+(Data!D2:D192*$P$3)), ARRAYFORMULA((Data!$C1:C191<>$O$4)+(Data!D2:D192*$P$4)), ARRAYFORMULA((Data!$C1:C191<>$O$5)+(Data!D2:D192*$P$5)), ARRAYFORMULA((Data!$C1:C191<>$O$6)+(Data!D2:D192*$P$6)), ARRAYFORMULA((Data!$C1:C191<>$O$7)+(Data!D2:D192*$P$7)), ARRAYFORMULA((Data!$C1:C191<>$O$8)+(Data!D2:D192*$P$8)), ARRAYFORMULA((Data!$C1:C191<>$O$9)+(Data!D2:D192*$P$9))) This is ugly, and very slow to load. Is there a way to create a function range to handle the same checks on multiple rows, and crunch it into a single formula?
Here is another monstrosity (this one has less repetition) for you:
=QUERY(
{IGNORE!A2:J, IGNORE!P2:P},
"SELECT * "
& "WHERE Col3 is not null "
& IF(COUNTIF(P2:P9, False) = 0, "", "AND NOT Col3 MATCHES '^" & JOIN("$|^", IFNA(FILTER(O2:O9, P2:P9 = False))) & "$' ")
& IF(COUNTIF(A2:K2, ">0") = 0, "", "ORDER BY Col" & JOIN(", Col", IFNA(FILTER(COLUMN(A2:K2) & IF(COLUMN(A2:K2) = 1, "", " DESC"), A2:K2)))),
0
)
Your checkboxes should remain. The second row can have just True/False values, no need for column number (a simple change will be needed COUNTIF(A2:K2, ">0") -> COUNTIF(A2:K2, True)). Also consequent sort works now (but only in the actual order of columns: if checked 1, 3, 4 then it will be sorted first by 1, then by 2, then by 4). You could place another config table on the right about sorting, where you would select all the columns you wish to sort by, their mutual order, and desc/asc for them.
Edit: added IFNA so FILTER won't return an error, changed multiple ANDS to MATCHES and simple regexes.
I want the Slicer in Power BI to select the most recent date of the selection to be selected automatically.
Here is an example of the drop down:
https://i.imgur.com/IykHSlI.png
This drop down differs from the Client selection.
I solved this issue the following way:
I created one Report with a filter to Default_Date (which opens first)
I used a Calculated Column [Default_Date] to populate the filter (which is hidden)
In my case the user wanted to see Yesterday's data as the default date so I selected 'Yesterday' on my filter.
Then I put a button that opens another duplicated copy of the Report [Hidden Tab] that contains a full calendar filter, so the user can select any other dates he likes, this hidden report has another button that returns the user to the main report [if he wants to].
picture of my filter (which I collapse and hide under a color box/banner)
Here is the formula for the calculated column (used in the filter):
Default_Date =
VAR TodaysDate =
TODAY()
VAR YesterdayDate =
TODAY() - 1
VAR reportDate =
SWITCH(TRUE(),
'Calendar'[Date] = TodaysDate, "Today",
'Calendar'[Date] = YesterdayDate, "Yesterday",
"Before Yesterday"
)
RETURN
reportDate
Use Default_Date in your filter, and you can replace TODAY() with
CALCULATE(Max(Table[Date]),All(Table))
and remove what you don't need.
If you want to get the Last Date of selected items, then
CALCULATE(Max(Table[Date]),ALLSELECTED(Table))
Table may need to be in quotes to work: 'Table'[Date]
I hope this helps.
There isn't to set a default value in Power BI, but there are a few around about ways. First you can try Persistent Filters that can preserve the filters selected. The other option, is to create in your data set, if you have a calendar table, or are able to add it to your column a current date flag, that you can apply as a filter to your report.
For example you can use the TODAY() to return todays date, and check against your date column.
Calculated column = IF(MONTH(TODAY()) = MONTH('table'[DateColumn]) && YEAR(TODAY()) = YEAR('table'[DateColumn]), "Y", "N")
You can run the report and it will always filter on the latest date, however you will have to remove the filter if you want to see other dates. You could set up bookmarks so that you can easily add/remove filter to the report. So you would have one bookmark with latest date, and the other to remove it. You can allow the slicer box to appear when you select the 'remove current month' bookmark
Hope that helps
I have a SRSS report using a SQL Query that uses that FilteredViews to allow for the report to use the "Run on current record". This works great but it adds a "Last X Days" and sets it to 30. It there someway to change that or better yet, get rid of it altogether? This is my query for reference:
SELECT CRMAF_Quote.QuoteNumber, CRMAF_Quote.Name, CRMAF_Quote.CreatedOn, CRMAF_Quote.CustomerIdName, CRMAF_Quote.OwnerIdName,
CRMAF_Quote.Name AS Expr1, CRMAF_Quote.BillTo_Line1, CRMAF_Quote.BillTo_Line2, CRMAF_Quote.BillTo_Line3, CRMAF_Quote.BillTo_StateOrProvince,
CRMAF_Quote.BillTo_PostalCode, CRMAF_Quote.BillTo_Telephone, CRMAF_Quote.BillTo_Fax, CRMAF_QuoteDetail.lineitemnumber, CRMAF_QuoteDetail.Quantity,
CRMAF_QuoteDetail.productdescription, CRMAF_QuoteDetail.BaseAmount, CRMAF_QuoteDetail.ExtendedAmount, CRMAF_Quote.DiscountAmount, CRMAF_Quote.TotalTax, CRMAF_Quote.TotalAmount,
CRMAF_Quote.RevisionNumber, CRMAF_SystemUser.Address1_Telephone1,
CRMAF_SystemUser.InternalEMailAddress, CRMAF_Product.productnumber, CRMAF_Product.Name AS ProductName
FROM FilteredQuote as CRMAF_Quote JOIN
FilteredQuoteDetail as CRMAF_QuoteDetail ON CRMAF_Quote.QuoteId = CRMAF_QuoteDetail.QuoteId LEFT OUTER JOIN
FilteredProduct AS CRMAF_Product ON CRMAF_QuoteDetail.productid = CRMAF_Product.productid LEFT OUTER JOIN
FilteredSystemUser as CRMAF_SystemUser ON CRMAF_Quote.OwnerId = CRMAF_SystemUser.SystemUserId
Attached is a screenshot of the 30 days it adds.
Thanks!
From your list of available reports - you should be able to select your report and then from the ribbon select Edit Default Filter. There you can change or eliminate the filter that automatically is added.
I am trying to combine all days of each month into a date.
My query as off now:
SELECT
inventory_items.acquired_at AS Date_Acquired,
products.name AS products_name,
SUM(inventory_items.primary_quantity) AS inventory_items_primary_quantity
FROM
inventory_items inventory_items INNER JOIN customers customers ON inventory_items.source_id = customers.id
INNER JOIN products products ON inventory_items.product_id = products.id
GROUP BY
MONTH(Date_Acquired),
products_name
ORDER BY
MONTH(Date_Acquired)
I have a general idea of what to do, but not really sure how to implement it.
As I understand you and your Date_Acquired is an instance of sql Date type
you can gat day of months as pasting below code inside a textfield
(new SimpleDateFormat("d")).format(new java.util.Date())
which suppose to give you numbers like 1,2,3,...18,19...
Extra:
(new SimpleDateFormat("M")).format(new java.util.Date()) for month
(new SimpleDateFormat("yyyy")).format(new java.util.Date()) for year
(new SimpleDateFormat("d")).format(new java.util.Date())+" - "
+(new SimpleDateFormat("M")).format(new java.util.Date()) for getting a value like 28 - 01
What database? A typical SQL database result can only contain one data value per field. So you will not be able to retrieve all the products.name values in one result grouped by the month. If you retrieve all the results under a specified month you can aggregate them later on.