Filter Previous Data DAX on condition - filter

Imagine I have the following dataset.
Product / IsOpen / Date
1 / 0 / 21 / 05 / 2009
1 / 1 / 22 / 05 / 2009
How can I filter/delete data previously to the first IsOpen = 1 ??
By creating a new table or even in Powerquery.
I just want data starting from its first IsOpen = 1.
Thanks!

Starting with this table in Power Query:
Sort by the "Date" column. (Click the down arrow button at the top right of the "Date" column and then select "Sort Ascending".) The table will basically look the same, except the dates will be in order and the down arrow button will change to this:
Add an index. (Click the "Add Column" tab and then "Index Column".)
Group by "IsOpen" and determine the minimum index value for each "IsOpen" value. (Click the "Transform" tab and then "Group By". Then fill in the pop-up window like this:
...and click "OK".) You'll see this:
Filter out the 0's in "IsOpen". (Click on the down arrow button at the top right of the "IsOpen" column and then deselect "0" in the list.)
You'll see this:
Remove the rows with 0's in "IsOpen" that occur before the first 1. (Here is the "trick" that does what you want. I found it on Ken Puls's blog, "The Ken Puls (Excelguru) Blog":
Click the "Fx" to the left of the formula bar and overwrite what appears with this:
= Table.Skip(#"Added Index",#"Filtered Rows"[MinIndex]{0})
Then press enter and you'll see this:
Notice the 0 "IsOpen" that occurred before the first 1 "IsOpen", which was at "Index" 0, is now gone.)

Related

Google Sheets Query using dependent dropdown

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)

Add timestamp, duration, developer's note, and relocate affected row based on a "Resolved" drop-down selection

I am working on a tracking document for work for software errors: https://docs.google.com/spreadsheets/d/1UNAUm23iAOlc4VqgW591gGBU758RddcGNdW2SDYCvk8/edit#gid=258517814. When a developer has completed a bug fix, they select "Resolved" from a drop-down in Column A. I'm trying to accomplish 3 things with a script:
1) When "Resolved" is selected in Column A on any row, a date/time stamp is entered in Column K, and a duration is calculated in Column L. I've accomplished this much with my script "ResolvedTimestamp".
2) Right after adding the timestamp and duration in the first step, I'd like a box to pop up that has a large text field for a developer to add notes to the user. Once finished, they click a button that says "OK". The notes entered into this box will populate the cell in Column C for the resolved row.
3) After the timestamp, duration, and developer's notes are added, the resolved row will move from the sheet "Form Responses" to the sheet "Resolved. Preferably, they would be added on top of everything else, on Row 2 (since Row 1 is for headers). That way, newest resolved rows are on top. The row would disappear from "Form Responses".
Can someone help me add #2 and #3 to my existing script? Thank you for the help! Here is the script I have that does #1, for reference:
function onEdit(e) {
//Add Resolved timestamp and duration
var value = (typeof e.value == "object" ? e.range.getValue() : e.value);
if (e.range.columnStart == 1 && value == "Resolved") {
e.range.offset(0, 10).setValue(new Date());
}
if (e.range.columnStart == 1 && value == "Resolved") {
e.range.offset(0, 11).setFormulaR1C1('=R[0]C[-1]-R[0]C[-8]-((weeknum(R[0]C[-1])-weeknum(R[0]C[-8]))*2)');
}
}

Show Different category name in tooltip in spotfire bar chart

We have a requirement for showing ID in category axis and description of same ID in tooltip.
I have multiple columns in my data like value 1 ,value2,value 3 etc. value 1, value 2 are columns.
I am putting this on value axis as an expression like Sum([value 1]) as [AC 6076 ], Sum([Value 2]) as [AC 6078 ], etc. that is this will hardcoded as IDs in category axis
So my category axis is column names. that is <[Axis.Default.Names]> .
please see the attached picture. It's the description against a column not a row.
It would be an expression in tooltip which may be something like
First(Case when '${Axis.Y.DisplayName}'='AC 6076' then "description 1" when '${Axis.Y.DisplayName}'='AC 6078 ' then "description 2" else " Description 3" end )
This expression is not showing correct value. it wil always show "Descrition 3"
i want to show this IDs(column names in category axis) and a description for each of these column names in tooltip. please have a look at the picture attached.
Atatched picture
Thanks
First(CASE
WHEN '${Axis.Y.DisplayName}'='AC 6076' THEN "description 1"
WHEN '${Axis.Y.DisplayName}'='AC 6078 ' THEN "description 2"
ELSE " Description 3"
END)
this always evaluates to your ELSE condition because ${Axis.Y.DisplayName} will always be the full display name for the axis, not the individual columns (i.e., "AC 6076, AC 6078").
you will need to add your description text to your data somehow. this is a little convoluted and will require some tweaking on your end, but the principle is the same.
this is assuming your table is something like this:
key val1 val2
a 1 4
b 2 5
c 3 6
from the menu, select File..Add Data Tables...
click Add then select the data table powering your visualization from the From Current Analysis heading
expand the Transformations pane at the bottom of this dialog
choose a Pivot transform and click **Add...*
leave everything default except for Transfer columns..., where you should add only the columns you wish to sum (e.g., [value 1] and [value 2])
OPTIONALLY change the naming scheme to just %T
click OK
your table now looks like (ignoring optional steps):
Sum(val1) Sum(val2)
6 15
choose another transform, this time Unpivot, and click **Add...*
add all columns to Columns to transform
click OK
now you have:
Category Value
Sum(val1) 6
Sum(val2) 15
choose one last transform: Calculate new column and click **Add...*
enter your case statement that will determine the description and name the column "Description" or something
click OK
click OK
your final table will resemble:
Category Value Description
Sum(val1) 6 This is the sum of value 1
Sum(val2) 15 This is the sum of value 2
on your bar chart, the category axis expression should be Category and value should be Sum(Value) (assuming you didn't change the column names in step 9)
add a new line to the tooltip with an expression First([Description]), or whatever you named the new column in step 12
whew. it's a lot of steps but it works. the goal is to get the description data into it's own column so you can put it in the tooltip. since your data is aggregated and doesn't exist in its own column, this is the only way I can think of doing it.

Spotfire Expression Value for Max(Row Count)

I'm trying to make a Calculated Value Control expression on the below columns:
Row Count | Date | Value
What I want to get is the Value for the 'newest' date, which will also be the highest row count. How can I write an expression to get this, it seems like it ought to be simple. I'm having trouble writing it in only expression language, without SQL.
Using the expression below you can limit the records in your table to those with the highest (aka most recent) date which should have your Value of interest.
[Date] = Max([Date])
You can do the same with row count since you mentioned the record of interest being the highest row count:
[Row Count] = Max([Row Count])
If you're looking to create a calculated column you can use a case statement to spit out the value:
case when [Date] = Max([Date]) then [Value] end
Lastly, should you want to display this value in a Text Area to show off your value you can utilize the calculated column above:
1) Create a new Text Area
2) Type some text about what it is: "Value for newest Date: " (optional)
3) Click "Insert Dynamic Item" -> "Calculated Value"
4) Under "Data" ensure the appropriate data table is selected. Note: You can uncheck the "Use Current Filtering..." box here if you do not want your value to update as you filter.
5) Under Values, utilize our calculated column with "Max" wrapped around it to avoid Summing duplicate values:
Max(CALCULATED_COLUMN)
Here is a screenshot of my work with random filler dates and values: http://i.imgur.com/hFapS8c.png
The larger text is to show the calculated value dynamic items. I used Max([Date]) for the date value.

Qlikview, how to create an expression which does not change with listbox selection?

Example, I have table below..
Week, Quantity
1, 10
1, 15
1, 10
2, 20
2, 30
3, 10
3, 50
I also have a list box for 'Week' which is current selected on week 2.
Now, I want to create text object which shows the value of sum of quantity of week 1 (ie. 35), which will always show that result even when the list box is selected on week 2. How can I achieve this?
Currently I managed to do an expression which sums week 1 but as soon as I select week 2 it shows 0 ....
Enter the following to your textfield:
= 'Sum week 1 : ' & sum({$<Week={'1'}>}Quantity)
Use the '&' to concat values. And use the set analysis (Page 799 of the QlikView Reference Manual) to select the reqired values.
sum({$<Week={'1'}>}Quantity)
Read this like: Sum the values of 'Quantity' Where 'Week' is 1.
Replace the '$' with '1' and the expression will ignore current selection
e.g.
sum({1<Week={'1'}>}Quantity)
do this:
sum({<Week={'1'}>}Quantity)
That is basically telling Qlikview regardless of what is selected in Qlikview, that expression will always calculate as if Week 1 is selected.

Resources