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
gluizqueiroz
Resolver I
Resolver I

How to separate each quarter in 3 lines with month and divide a specific number

I have the following table:

 

GroupQtyQuarterRegion
Eletronics4201°/2018North
Food6001°/2018North
Cloths4801°/2018North
Eletronics3002°/2018North
Food3602°/2018North
Cloths4502°/2018North

 

I need to divide each quarter in 3 lines with month and divide the column Qty by 3 for each month, like the following:

 

GroupQtyQuarterRegion
Eletronics140jan/2018North
Eletronics140feb/2018North
Eletronics140mar/2018North
Food200jan/2018North
Food200feb/2018North
Food200mar/2018North
Cloths160jan/2018North
Cloths160feb/2018North
Cloths160mar/2018North
Eletronics100apr/2018North
Eletronics100may/2018North
Eletronics100jun/2018North
Food120apr/2018North
Food120may/2018North
Food120jun/2018North
Cloths150apr/2018North
Cloths150may/2018North
Cloths150jun/2018North


Is there any way to achieve this with Power Query? 

1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

Hi @gluizqueiroz 

Please paste below formula in advanced editor to check the workaround.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs1JLSnKz8tMLlbSUTIxMgCShoc26BsZGFoAmX75RSUZSrE60Upu+fkpQAEzA5wqnHPySzLApljgVINimzHYLCM8thmb4VSBsM0Uu5pYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Group = _t, Qty = _t, Quarter = _t, Region = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Group", type text}, {"Qty", Int64.Type}, {"Quarter", type text}, {"Region", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Quarter_New", each if [Quarter] = "1°/2018" then "jan/2018,feb/2018,mar/2018" else if [Quarter] = "2°/2018" then "apr/2018,may/2018,jun/2018" else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Quarter"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns", "Quarter_New", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Quarter_New.1", "Quarter_New.2", "Quarter_New.3"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter", {"Group", "Qty", "Region"}, "Attribute", "Value"),
    #"Removed Columns1" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Divided Column" = Table.TransformColumns(#"Removed Columns1", {{"Qty", each _ / 3, type number}})
in
    #"Divided Column"

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-cherch-msft
Employee
Employee

Hi @gluizqueiroz 

Please paste below formula in advanced editor to check the workaround.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs1JLSnKz8tMLlbSUTIxMgCShoc26BsZGFoAmX75RSUZSrE60Upu+fkpQAEzA5wqnHPySzLApljgVINimzHYLCM8thmb4VSBsM0Uu5pYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Group = _t, Qty = _t, Quarter = _t, Region = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Group", type text}, {"Qty", Int64.Type}, {"Quarter", type text}, {"Region", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Quarter_New", each if [Quarter] = "1°/2018" then "jan/2018,feb/2018,mar/2018" else if [Quarter] = "2°/2018" then "apr/2018,may/2018,jun/2018" else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Quarter"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns", "Quarter_New", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Quarter_New.1", "Quarter_New.2", "Quarter_New.3"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Split Column by Delimiter", {"Group", "Qty", "Region"}, "Attribute", "Value"),
    #"Removed Columns1" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Divided Column" = Table.TransformColumns(#"Removed Columns1", {{"Qty", each _ / 3, type number}})
in
    #"Divided Column"

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.