"Subquery" in Power BI - subquery

I have two tables.
Table 1
Table 2
As you can see, there is a link between ID from Table 1 and IdPays from Table 2 (the link is obviously the letter A,B,...). My question is, is it possible to make a link between the two tables without having to duplicates any column ? Is it possible to create a link immediately on the letter of the ID column ?
Thanks for your help.

Anything can be done, but from perspective of data structuring (and performance) it is really a bad idea.
= Table.AddColumn(Table1, "Table2", (Earlier) => Table.SelectRows(Table2, each [IdPays] = Text.Start(Earlier[ID],1)), Value.Type(Table2))

Related

Comparing two tables of different size, with multiple columns in VBA

Looking to use VBA to compare two tables, with three columns each against each other. Beginner here and very lost.
They may have a different amount of entries each, and there may be some in table A that aren't in table B, and vice versa
Some of the individual Columns may match but trying to work out how to make sure all three columns are compared as one against all three columns in the other table
For example
xyz123 55.50 12/07/21 if compared with XYZ123 54.55 12/07/21 will show up as not a match, because the middle column is a different number.
Have attached a picture below. For the most part, and unlike the photo, each table will be in a completely random order, and its unlikely that there will be the same entry in table 1, row 1, as table 2 row 1
Ideally, I'm trying to create two new table to the right of the original tables, the first one being the entries table 1 has, that table 2 does not have. The second one being the entries table 2 has, that table 1 does not have.
Have attached an example below of the end result I'm looking for out of this. The four rows on the left are entries that the first table has but the second table doesn't, and the rows to the right are all entries that the second table has, but the first table does not.
I've tried to search on this but haven't found something that matches what I've got, and I'm struggling to adapt someone else's code to my specific problem
Any help on this would be greatly appreciated
Maybe not a direct answer to your problem but is this data also in a database somewhere or are you familiar with Ms Access? As you could open the tables in Access, and it is pretty easy to do this kind of thing with data bases.
If not, then yes, it is do able with VBA. Numerous ways of doing it.
The simplest is to scroll through one table a line at a time and compare it with every row in the other table and match or not. This will work with small tables and be easy and quick but for large data tables it would be wasteful and may take a long time to complete.

number listing for conditions in sqlite

I have a table in which I am trying to create a column that will increment based on conditions being valid.
In my example, I need to update the department count where the department = Marketing. Anyone have a good way to do this using SQLite?
Current Table
Name Department Department_Count
James Accounting NULL
Jennifer Marketing NULL
Micheal Warehouse NULL
Natalie Marketing NULL
Rebecca Marketing NULL
Update Table
Name Department Department_Count
James Accounting NULL
Jennifer Marketing 1
Micheal Warehouse NULL
Natalie Marketing 2
Rebecca Marketing 3
Edit:
Currently, I insert rows where the department is 'Marketing' into a new table and then I used primary key or rowid to create an auto increment so I can number these types of items.
This requires me to create a new table which is not the best since it takes up so much space and the table is redundant since I have the underlying data in this original table already.
I'm using python to interact with my database, if that helps with solving this problem.
UPDATE
Actually, thinking about it a little further, you may not need a trigger:
INSERT INTO Table (Department, Department_Count)
VALUES (?, (SELECT MAX(IFNULL(Department_Count, 0)+1 FROM Table WHERE Department = ?))
may give you what you want.
Original Answer
You cannot do this declaratively, but you can probably accomplish what you want proceduraly using a trigger.
Two possible strategies:
Use an AFTER INSERT trigger to execute an UPDATE statement against the most recently inserted row (RowID will be available AFTER INSERT) to set the Departement_Count column to a SELECT expression based on the current data in the table.
Use an INSTEAD OF trigger to perform an alternate INSERT combining the values from the NEW cursor with a similar SELECT statement to get the maximum value (plus 1) from the Department_Count column.

Pivot table with registers duplicate in 2 row

I have a question about how to summarize a list of data, I attached an image of how the data is presented.
The question is how to determine (summarize) the total of activities per unit considering that a person works in 2 units.
You could define that the person working in A / B does 50% of activities for each unit.
As the list of registers is very extensive the idea is to be able to automate, try with a PivotTable and did not give me result.
Any suggestions would be appreciated (xls, sql, etc).
data
http://ge.tt/381feDj2 -> Excel fILE
Am really not the best of people when it comes to Pivot Tables, but assuming i know what you are asking for.
1) Add one extra column (dummy) and just put 1 in it, this will be used to sum the number of events that the criteria occurs.
2) Select the whole table and then Insert=>Pivot Tables
3) Click Ok
4) Set Rows (fecha); Values (dummy); and the rest to Filters.
Then you can choose to filter your output the way you want. If you want A and A/B you can select multiple in the filter options.

Find position from row and tag with another table?

I have table where one of my field is 40 char long and the values are coming like this
00A000GB000C000000000F000000D0000000000E
now I need to find out the position for each character populated and join with another table, another table has field call position. For Example
from the field above, A is 3rd position, G is 7th position, B is 8
so I have to find the position for the fields populated(<>0) and then join with another table.
Please let me know how can I resolve this.
I think the community will need some more information to help with this question.
A couple questions I have when looking at this is:
What type of database are you using?
Are you looking to actually JOIN a table with another or are you talking about populating another table with data? If it is a join what type of data are you using to link the 2 tables?
Are you wanting to do this with SQL?
What programming language are you working with?
It sounds to me like you are going to need to do some programming to handle this one. Not knowing the answers to the above questions I am taking a stab at things and would recommend extracting the data from the database, processing the data to find the position, then select from the second table based on your processed data.

Can you nest Excel data tables?

I have an Excel workbook that utilises a data table (A).
I now want to create another data table (B) that effectively sits on top of the other data table. That is, each "iteration" of B calls A.
This approach fails although I cannot find any documentation about data tables that indicates that this would not work.
Basically I'd like to know if anyone has tried this before and whether I am missing something?
Is there a workaround? Do you know of any documentation that spells out whether and why this is not supported?
No.
I tried this at length some years ago in both xl03 and xl07 and my conclusion was that it can't be done - each data table seems to be an independent one-off run, they don't talk if you try to link them
I couldn't find any documentation on this issues either on the process, or for anyone else looking at a similar problem.
I want to share my experience using the data tables.
We have found a workaround for this problematic.
If you have two variables A & B that need to run into a datatable and get one or multiple result.
What we've done is :
Set any combinaison (binari combinaison) for A & B and put an id for each of this combinaison (A=0 & B=0 => id=1)
So you will then run one data table with a length of A*B.
The default here is the length to calculate those data (7min with 25 data table & 2 data table with a length of 8000 rows).
Hope it help !

Resources