Convert SAP BI hierarchy to flat table - excel

I have a table:
Old table
Level 1 is top level. CC is the smallest unit inside our company.
What I want to do is convert this table into a flat table with additional column like level 1 / level 2 / Level 3, which show parent department of each node,
e.g. 100111 |CC |3 |IS// |IS/ |IS.
New Table
Using Excel I can do it easily by using some conditional formula and copy the cell above if current cell is CC.
My process is like this: SAP Application (export)-> .xls file (without Level and Parent Columns) -> creating new column for level and parent node with power query -> make new column (level 1 - 6) like example in the new table.
For Column Level 1 i use this formula:
If(B2=1;A2;D1)
and i fill it down for the rest. In my data, the first row is always level 1.
For Level 2:
=IF(B2=2(//because is Level 2),A2,IF(B2<2,"",E1))
And i repeat the same formula for other Column.
Can someone suggest me a solution for this problem?

I think the Power Query equivalent of your first formula would be to Add a Column with this formula:
if [Level] = 1 then [Department] else null
I would follow that with a "Fill / Down" step (from the Transform ribbon).
The subsequent formulas would look similar, e.g. for Level 2
if [Level] = 2 then [Department] else null
Follow each with a "Fill / Down" step and you should be done.

Related

generate a inventory item coding in excel

Can you support me in the following I need to create coding for inventory items
I built the structure ( 4 letters, and 4 digits)
(Warehouse Type, Warehouse Group, Family, Sub-Family) after that add a sequence 4 numbers
if the item in Warehouse Type ( A ), Warehouse Group (B ), Family(C), Sub-Family(D),
I need to generate a code ABCD0001, the following item if it from the same warehouse, group,family, and sub-family take generate code (ABCD0002),
BUT if the item has any different thing in structure starting from 0001
like if the item:
Warehouse Type ( B ), Warehouse Group (B ), Family(C), Sub-Family(D)
the code should be BBCD0001
what should I do to achieve this, I have almost 1200 items and I need to add a code for all of them
Create 4 lookup tables (for sample I have made two for Warehouse Type & Group seen on the left). Then apply the mapping you wish to have for each Type, Group, Etc.
In your raw data (on the right) create two helper columns: one to create your warehouse string and another to count the instances of those strings i.e. your sequence number
The formulas are below. Add them to first row of raw data and drag down to create the full list of unique keys
I2 = VLOOKUP(G2,$A$1:$B$6,2,0) & VLOOKUP(H2,$D$1:$E$6,2,0)
J2 = I2 & TEXT(COUNTIF(I$2:I2,I2),"0000")
In cell I2 you will need to combine 4 VLOOKUPS so just copy the method shown here. One for Type, Group, Family, & Sub-Family.

Excel Populate table with continuus values

In MS Excel I have one table with few values (i.e. 3, no fix length) and in second table these values has to be repeated lot of time (i.e. 7 times). I do not understand how to provide this with normal Excel formulas/functions.
Table 1:
ABC
Table 2 (target table):
ABCABCA
how stupid am I. Is used wrong name of function index: the correct is =INDEX(Table1!A$1:A$100; 1; MOD(ROW();COUNTA(Table1!A$1:A$100))+1)
and this is added in each row of table 2

How to validate source data using a Range validation table in Excel Power query

Can anyone please help me on this?
I am trying to validate the source data in 3 columns BU - Act - Dept in the Range validation Data [BU - Beginning Act - End Account - Beginning Dept - End Dept] (screenshot attached).
BU is a single column in validation table but Act & Dept columns are range columns. I need to check if the BU - Act - Dept combo exists in Range data.
So does Power query has any functionality to validate the source data using a nested join?
This needs to be done in Excel power query and not formulas because the validation Range file has more than 1 million records.
I'm not sure how efficient this is, but it works in principle.
I'll assume you have both tables loaded into the Query Editor with names Source and Validation.
First, choose the Source query and merge in the Validation table, matching on Source[Unit] = Validation[BU] for a left outer join.
Once merged, expand all the columns except Validation[BU]. This will give you a table with more rows since it will pull over every row in Validation that corresponds to the Source[Unit].
Now you can write a validation Status column. Add Column > Custom Column:
= if [Account] >= [Beg Act] and [Account] <= [End Act] and
[Dept] >= [Beg Dept] and [Dept] <= [End Dept]
then "Valid" else "Invalid"
Now that you have this column, group by the first three columns and take the max over the new custom column, Status. This should reduce your table back to its original size and give "Valid" in the Status column if that row matched any of the conditions that were pulled over from the Validation table, otherwise "Invalid".

Break ties in RANKX Powerpivot formula

I can rank my data with this formula, which groups by Year, Trust and ID, and ranks the Areas.
rankx(
filter(Table,
[Year]=earlier([Year])&&[Trust]=earlier([Trust])&&[ID]=earlier([ID])),
[Area], ,1,Dense)
This works fine - unless you have data where the same Area appears more than once in the same group, whereupon it gives all rows the rank of 1. Is there any way to force unique rank values? So two rows that have the same Area would be given the rank of 1 and 2 (in an arbitrary order)? Thank you for your time.
Assuming you don't have duplicate rows in your table, you can add another column as a tie-breaker in your expression.
Suppose your table has an additional column, [Name], that is distinct between your multiple [Area] rows. Then you could write your formula like this:
= RANKX(
FILTER(Table,
[Year] = EARLIER([Year]) &&
[Trust] = EARLIER([Trust]) &&
[ID] = EARLIER([ID])),
[Area] & [Name], , 1, Dense)
You can append as many columns as you need to get the tie-breaking done.

How get rows with oldest date per year

I have task in excel. I think I show you it on example. Let say we have table as:
ID date
1 2015-03-11
1 2015-05-13
2 2013-01-10
2 2010-05-11
1 2014-09-19
2 2013-04-01
I have to make some operations to get rows with oldest date per every year. So I should have:
ID date
1 2015-03-11
1 2014-09-19
2 2013-01-10
2 2010-05-11
I will grateful for any help. Thanks in advance!
This is but one option. I like using SQL for this type of work and since Excel can connect to itself as an ODBC data source, that's just what I did here...
Create a Named range in excel (I called mine SomeTable) I do this by selecting the range in question and clicking in the drop down field to the left of the formula space that usually lists the selected cell (B11 in image below)
I then select data, from external sources and select the option for Microsoft Query (ODBC). Select new data source give it a name (Excel File name) Select microsoft excel driver. click connect. browse to where the file is containing the named range (Some table) Select ok and then in the 4th option select the named range (SomeTable)... select a place to put the table on a worksheet.
Now click in the "table" data it creates and go to the data menu properties. and enter the following in the definition tab under command text
.
Select ID, Date
FROM SomeTable ST
INNER JOIN
(Select MIN(date) as mDate, year(date) as mYear
FROM someTable
Group by year(date)) A on
ST.Date = A.mDate
If all done correctly you should get results like this:
Column EF is the source table named "SomeTable"
A10 is where I chose to put the table
B20 is where the SQL used to get the max per year
was put.

Resources