power query M language accessing Key (name/value) in a record - powerquery

We can access table rows as they are lists with the syntax below.
#tableName{index}
It returns us a key-value pair in record format. Now I want to access the column name which is 'key' without copying and pasting the column name.
Is it possible in the M language?
Yes, with help of user #Storax I was able to achieve what I needed: To take value of Column name; Below is code. Thanks to Storax
Table.Column(
Table.DemoteHeaders(Source),
Table.ColumnNames(Table.DemoteHeaders(Source)){0}){0}

Related

Informatica - Concatenate Max value from each colum present in multiple rows for same Primary Key

enter image description here
I have tried traditional approach of using Agg (Group By: ID, Store Name) and Max(Each Object) columns separately.
Then in next expression, Concat(Val1 Val2 Val3 || Val4).
How ever, I'm getting output as '0100'.
But, REQUIRED OUTPUT: 1100
Please let me know, how this can be done in IICS.
IICS is similar to the Powercenter on-prem.
First use an aggregator.
in Group By tab add ID, Store Name
in Aggregate tab add max(object1)... please note to set data type and length correctly.
Then use an expression transformation.
link ID, Store Name first.
Then concat the max_* columns using pipe -
out_max=max_col1||max_col2||... please note to set data type and length correctly.
This should generate correct output. I think you are having wrong output because of data length or data type of object fields. Make sure you trim spaces from object data before aggregator.

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).

Combine Tables matching a name pattern in Power Query

I am trying to combine many tables that has a name that matches a patterns.
So far, I have extracted the table names from #shared and have the table names in a list.
What I haven't being able to do is to loop this list and transform in a table list that can be combined.
e.g. Name is the list with the table names:
Source = Table.Combine( { List.Transform(Name, each #shared[_] )} )
The error is:
Expression.Error: We cannot convert a value of type List to type Text.
Details:
Value=[List]
Type=[Type]
I have tried many ways but I am missing some kind of type transformation.
I was able to transform this list of tables names to a list of tables with:
T1 = List.Transform(Name, each Expression.Evaluate(_, #shared))
However, the Expression.Evaluate feels like an ugly hack. Is there a better way for this transformation?
With this list of tables, I tried to combine them with:
Source = Table.Combine(T1)
But I got the error:
Expression.Error: A cyclic reference was encountered during evaluation.
If I extract the table from the list with the index (e.g T1{2}) it works. So in this line of thinking, I would need some kind o loop to append.
Steps illustrating the problem.
The objective is to append (Tables.Combine) every table named T_\d+_Mov:
After filtering the matching table names in a table:
Converted to a List:
Converted the names in the list to the real tables:
Now I just need to combine them, and this is where I am stuck.
It is important to not that I don't want to use VBA for this.
It is easier to recreate the query from VBA scanning the ThisWorkbook.Queries() but it would not be a clean reload when adding removing tables.
The final solution as suggested by #Michal Palko was:
CT1 = Table.FromList(T1, Splitter.SplitByNothing(), {"Name"}, null, ExtraValues.Ignore),
EC1 = Table.ExpandTableColumn(CT1, "Name", Table.ColumnNames(CT1{0}[Name]) )
where T1 was the previous step.
The only caveat is that the first table must have all columns or they will be skiped.
I think there might be easier way but given your approach try to convert your list to table (column) and then expand that column:
Alternatively use Table.Combine(YourList)

MS Access Custom Formatting: Currency in K

I am trying to create an appropriate Format table property of a specific MS Access table in order to achieve the display style described below. For example purposes, let the table name be example and the field that I am trying to format be dollars
When example!dollars.Value is 567.98, I wish to display $0.567K. I also wish to display 1,000.42 as $1.000K.
In another table storing larger values, I use the Format property string $#,##0,\K; ($#,##0,"K)"[Red];"| < $1K |"; --, which successfully displays the amount in K dollars; however, any values less than $1K cannot be displayed. This is not acceptable due to the scale of the values in the example table.
The most intuitive solution is to use the string $0,000\K and specify the thousands separator as . instead of ,. However, I do not know how to do this.
Any advice will be greatly appreciated!
This works for me:
Kamount = Format(Amount/1000, "$0.000K")
So divide by 1000, then format as needed.
Use the Format property string $0\.000\K

Open formula doesn't return name

I have written open formula in Pentaho Report Designer 5.0.1 as:
=SINGLEVALUEQUERY("SELECT name FROM income_product where order_no=1";)
Rather than writing a query on data set and call from SINGLEVALUEQUERY() I want the string value from the above query.
PRD doesn't complain about the above formula as syntax error; it just returns null/nothing. What (if anything) is wrong in that formula?
I want to write that formula to generate dynamic column name for a report having order number 1 or greater. Is there any other way to make the column name dynamic for a report?
By "Dynamic column name", I mean making different organization have unique income_product_order.
If I just assign the order_no of income_product it automatically gets income_product_name as the column name for all organizations.
Did you set up your connection correctly? try adding a query over that connection and paste that query there. Does it return any data?
This is a good blog post on the subject: https://www.on-reporting.com/blog/using-queries-in-formulas-in-pentaho/
You can enable the "Display the index columns (...)" option under Settings. It'll allow you to reference columns either by name or by index (column0, column1, etc.)

Resources