July 17, 2018
I started a new job and if I'd known what a mess their data is in I'd have had second thoughts
Latest issue is sales data actual and estimated in weekly stacked tables product code and Sun-Sat in columns then repeated underneath for a full 52 weeks of individual sections of data.
As the attachment
I think maybe its possible to separate at the 2 blank cells between each block of headers but not sure how to start.
I'll fix the way they store data eventually but I have 4 years of data to clean as well
John
July 16, 2010
Hi John,
I'm not sure there's an easy way to fix this data because there's a different number of rows in each group of weeks. i.e. there's no consistent pattern. My approach would be to create a separate table for each Sun-Sat range of rows, unpivot and then append.
Someone else might have a better idea.
Mynda
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
Hi John,
It is possible, but not easy.
To separate weeks, you can add an index column and a custom column to identify the beginning of another section, based on text "IPS CODE" from column 1.
If you fill down the Custom column, you will be able to group rows into different tables.
That was the easy part...
Each table must be now converted.
I used a double loop in the custom function that converts the tables:
Loops = List.Accumulate({8..21},Data1,(L1State,i)=>
List.ReplaceRange(L1State,i-1,1,
{List.Accumulate({0..RowsCount},{},(L2State,j)=>
if Text.Contains(if Data1{0}{j}=null then "" else Data1{0}{j},"CODE") then
L2State & {Text.From(L1State{i-1}{j}) & "|" & Text.From(L1State{i-1}{j+2})}
else L2State & {L1State{i-1}{j}})})),
The double loop is similar to what is usually done in vba:
For i=column8 to column21
For j=0 to tableRowsCount-1
if column 1 value contains "CODE" then replace date with Date & "|" & the value located 2 rows down (where we have EST or ACT)
Next j
Next i
There can be other solutions, it's just an idea.
Answers Post
The following users say thank you to Catalin Bombea for this useful post:
Mynda TreacyPower Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
You're welcome.
Anyway, it's not about M knowledge. In fact, the double loop is an unnecessary complication, the function can be created without editing M code, using user interface tools.
It's just imagination I think, to let imagination fly, you have to think different than normal excel tools.
Here is a function built with interface, will do the same thing (Est and ACT are not independent columns, they are attributes in the same column. It can be pivoted to make 2 columns though):
let
Source = tbl,
#"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Column1] <> "")),
#"Promoted Headers" = Table.PromoteHeaders(#"Filtered Rows", [PromoteAllScalars=true]),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"IFS#(lf)CODE", "Column2", "Column3", "COMMENTS", "Q#(lf) BOX FORMAT", "Column6", "Column7"}, "Attribute", "Value"),
#"Added Index1" = Table.AddIndexColumn(#"Unpivoted Other Columns", "Index", 0, 1, Int64.Type),
#"Checked Is Even" = Table.TransformColumns(#"Added Index1",{{"Index", Number.IsEven, type logical}}),
#"Added Custom1" = Table.AddColumn(#"Checked Is Even", "Type", each if [Index]=true then "EST" else "ACT"),
#"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"Index"}),
#"Extracted Text Before Delimiter" = Table.TransformColumns(#"Removed Columns1", {{"Attribute", each Text.BeforeDelimiter(_, "_"), type text}}),
#"Changed Type" = Table.TransformColumnTypes(#"Extracted Text Before Delimiter",{{"Attribute", type date}})
in
#"Changed Type"
1 Guest(s)