How might I filter out one half of a relationship set between values of two columns? - powerquery

I'm trying to isolate one half of the relationship set between two columns in a table. For instance, if I have a table like this:
It show a relationship set between A and B (or B and A) twice. Once for each direction of the relationship...first A to B and then B to A.
So how might I be able to identify and filter out the second half (direction) of the relationship set?
To achieve a result like this?
Is there a "simple" way?

There may be a more efficient way, but this should work:
Add a column which creates a sorted text value of the two columns, possibly separated by a character that won't appear in either column. You can do this by calling List.Sort on a list of the cell values, and then using List.Accumulate to join the strings. For example, the expression to use in Add Custom Column could be each List.Accumulate(List.Sort({[Column1], [Column2]}), "", (state, current) => state & ";" & current).
Use Remove Duplicates on the new column to get rid of the duplicate relationships (i.e. use Table.Distinct).
Remove the added column.

Related

how to fetch previous values of a table in oracle forms

My first task is to add two new columns to a table, first column stores the values of M and X fields values in a single column(as a single unit with a pipe separator) and second column stores O and Z fields values in a single column(as a single unit with a pipe separator).
second task selecting agency and external letter rating(shown in image) from drop down and after saving the form the value from fields M and X should move to N and Y and this values should be stored in table column that are created from task one, Now if we save the form the values should move to O and Z fields in forms and this should continue.
Can any one help me how to proceed with this and I don't know how to separate a column value into pieces and display on form.
Better if you propose any new method that does the same work.
Adding columns:
That's a bad idea. Concatenating values is easy; storing them into a column as well. But, then - in the next step - you have to split those values into two values (columns? rows?) to be joined to another value and produce result. Can you do it? Sure. Should you? No.
What to do? If you want to store 4 values, then add 4 columns to a table.
Alternatively, see if you can create a master-detail relationship between two tables so you'd actually create a new table (with a foreign key to existing table) with two additional columns:
one that says is value stored related to M or Y
value itself
It looks like more job to do, but - should pay off in the future.
Layout:
That really looks like a tabular form, which only supports what I previously said. You can't "dynamically" add rows (or, even if you could, that's really something you should avoid because you'd have to add (actually, display) separate items (not rows that share the same item name).

Power Query - conditional replace/clear entire cell in multiple columns

I'm trying to clear the entire cell if it doesn't contain a given keyword.
I've managed to do this for one column:
Table.ReplaceValue(#"PrevStep",each [#"My Column"], each if Text.PositionOf([#"My Column"],"keyword")>-1 then [#"My Column"] else null,Replacer.ReplaceValue,{"My Column"})
The problem is I need to iterate/repeat that step for a number of columns... the number of columns may vary and column names also may be different every time. I can have all those column names put into a list but I'm not able to use it.
The solution I'm looking for may look like this
for each ColNam in MyColumnsList
Table.ReplaceValue(#"PrevStep",each [#"ColNam"], each if Text.PositionOf([#"ColNam"],"keyword")>-1 then [#"ColNam"] else null,Replacer.ReplaceValue,MyColumnsList)
next
but this is not the VBA code but Power Query M - and of course the problem is with #PrevStep as I would see it like a recursions... again... do not know how to process.
Is the path I follow correct or should it be done some other way
Thanks
Andrew
Unpivot your columns to turn all the columns into two columns. Apply your replacement to the single value column then pivot it back into the original format

How do I FILTER cells based on two drop-down list conditions?

I need a FILTER formula to get an output of the cells within the range of the two labels matching the conditions from the two drop-down lists.
For example, given the below sheet, I need the output to be what's highlighted, given the two conditions from the drop-down lists:
I also need to be able to add more date rows, expanding downward.
I've tried using QUERY:
=TRANSPOSE(QUERY(Accounts!B2:F, "SELECT * WHERE B="""&B2&""" ",1))
This only gives me the row of contents (apple, carrot, cake, steak, soda).
Here you can find my solution:
https://docs.google.com/spreadsheets/d/1cWBLLmJx6mTlYrvPRvRE_y9NpBOJj_ILBgXmoB9suv4/copy
Note that when you merge cells, the value is only in the top one or the leftmost one. So if you have multiple rows for each data, you should multiplicate these cells.
I make additional column for this - first date I just copy and below it I insert a formula: (in H5)
=if(isblank(A5),H4,A5) - it says - if cell in column A is empty, take value from above, but if you find something there, put it here. Then I copy this formula down the sheet.
Then it gets easier.
To filter with data validation you have to first find right column using formulas INDEX and MATCH and then filter it against data values in additional column.
Does it work for you?

How to sort a Reporting Services table by an auto generated column

I have this table:
When executed, it looks like:
This table is sorted by alphabetical order. I would like to sort it by the column named "No Vencido", which is generated in runtime combining 2 dimensions of a cube (one dimension is called "Class 1", the other dimension is called "value".
How can i sort a table by an autogenerated field?
Thanks
You can sort by any sort of expression - SSRS will quite happily sort something like two fields concatenated together:
=Fields!Class1.Value & Fields!value.Value
Just be careful to make sure the sorting is applied at the appropriate level to avoid unexpected, i.e. make sure you don't have different sorting expressions in any row group or detail group if not required.
If No Vencido is the grouping expression, apply the sorting at the group level.
If you don't want to sort on an expression, you can create a calculated field for each row in the dataset with the expression =Fields!Class1.Value & Fields!value.Value and group/sort on that calculated field as required.
Edit after comment
OK, I think you need to apply a sort expression like this to the groups that apply to the Top and Otros rows:
=Sum(IIf(Fields!Clase_1.Value = "No Vencido", Fields!Monto.Value, Nothing))
This is still sorting by the total Monto for each row group, but only considering the rows where Clase_1 is No Vencido.
Once this is set up sort by A-Z or Z-A as required.

How to sort only those rows which have no blank cell?

I have a Google Spreadsheet with two separate sheets. The first one is just a big list of names and data, and the second is supposed to be a sorted listing of all the data on the first sheet (sorted by, say, last name). Here is the current way I am defining the second sheet:
=sort(sheet1!A2:L100, sheet1!D2:D100, TRUE)
Which works fine for the most part, except for one issue: in sheet1, some of the cells in 4th column (column D) are blank. How can I change the formula so that the sorting ignores such rows which has a blank cell in column D?
The formulas i tried but got undesirable results :
=arrayformula(if(istext(sheet1!D2:D100), sort(sheet1!A2:L100, sheet1!D2:D100, true), ""))
It sorted as desired but with one issue - blank cells were not pushed at the end but scattered in between the rows.
=arrayformula(sort(filter(sheet1!A2:L100, istext(sheet1!D2:D100)),sheet1!D2:D100, true))
Though the filter part does its job perfectly but when coupled with sort, it is giving an error : Mismatched range lengths.
To filter out the rows with blank cells in column D, you could do something like #2, but as the error message suggested, the second argument would need to be filtered as well to ensure the ranges are the same length. Fortunately there is an easier way, and that is to use column indices rather than ranges:
=SORT(FILTER(sheet1!A2:L100;ISTEXT(sheet1!D2:D100));4;TRUE)
Alternatively you can use the QUERY function for this sort of thing:
=QUERY(sheet1!A2:L100;"select * where D != '' order by D";0)
For anyone looking this, the accepted answer works great if filtering out blank cells that are truly blank, but if the cells contain formulas that evaluate to blank (""), ISTEXT will evaluate to TRUE and blanks will not be filtered out. I modified the accepted answer slightly to work in my situation, in which I had cells containing formulas (that evaluated to "") that I wanted to filter out:
=SORT(FILTER(sheet1!A2:L100,sheet1!D2:D100 <> ""),4,TRUE)

Resources