Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jpt1228
Responsive Resident
Responsive Resident

Combining data with Year - Month rows

Hello, I have multiple data files that are delivered on a quarterly basis. The supplier will not change the format. There are several lines of header and then the data begins in the rows, the date is in Year - Month Number in the columns. Then the second data file is below that with the same headers and next  3 time periods Years - Months. I was deleting the top rows and unpivoting the 3 date columns but the  query editor is combining the 2017 - 1 with the 2017 - 4 thus I only have 2017 - 1, 2017 - 2, and 2017 - 3 for dates. The bottom ones don't come in correctly. Hopefully my explaination is clear.

 

I need to report this data that will be for 2017-1, 2017-2, 2017-3, 2017-4, 2017-5,2017-6 and then add in every 3 months when the new data is delivered.

 

image.png

2 ACCEPTED SOLUTIONS

Hi @jpt1228

 

I had a quick gap in my work and what I did was to first create a function in which I could get the data into the right format. As you can see below I added a new column which will keep the same row number for the same data. This enabled me to leverage this in the function.

 

Email Pic.png

 

Here is the function Code

(IndexNumber as number) =>
 let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8khNTEktUvDJzEtVMFTSUUJHsTrRShlIaoxwqEE2xxiHGpfU4uSizIKSzPw8oFBAYnI2kArOrEoFUqF5mSXFQNrIwNBcQRfsFCjTCME0BhvjWZKaC1ZgBsSGFgr+USAabpUhQpERMYqMsSgyxOGzQRRCJgimKYJphjuEoO4yhtmFNYSMYSqQFaGHkAnc0SZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1),
    #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each Number.IntegerDivide(_, 7), Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Integer-Divided Column", each [Index] = IndexNumber),
    #"Removed Top Rows" = Table.Skip(#"Filtered Rows",3),
    #"Removed Columns" = Table.RemoveColumns(#"Removed Top Rows",{"Index"}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Columns", [PromoteAllScalars=true]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Description", "Pack", "Size", "Units"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Date"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Value", Int64.Type}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type",null,0,Replacer.ReplaceValue,{"Value"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Replaced Value",{"Units"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns1",{{"Value", "Units"}})
in
    #"Renamed Columns1"

 

Then I passed this function to the data, based on the same row number so that it would iterate over the data. To do this I created an almost identical table but I was just left with the Index Numbers, where I then "Invoke Custom Function" from the Add Columns Ribbon

 

Email Pic.png

And here is the end result.

 

Email Pic.png

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

View solution in original post

Hi @jpt1228

 

I did the divide by 7 because there were 7 rows which for each group.


Then in the last 3 lines it was doing the following:

  • I was replacing the Null value with 0
  • I then removed the column called "Units"
  • And then I renamed the column "Value" (which was from the Unpivot) to "Units"




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

View solution in original post

10 REPLIES 10

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.