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
Syndicate_Admin
Administrator
Administrator

Separate the values according to their type of sale.

Good as they are?

I need to separate the values according to their type (VEN, CAM or DEV) each row has one of these values. what I need to achieve is to be able to break down the 3 values into different columns.

Any idea of how I can do it?

joacoabeleira_0-1657893676740.png

Best regards.

2 REPLIES 2
v-kkf-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

 

What data do you want to populate with when you convert column [Tipo] values to different columns? Assuming we use the Value column,

 

vkkfmsft_0-1658214609177.png

 

then please try the following code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jc6xDsIwDATQf/FcS+dzEtoRQUcYu1T5/9/AAYUsGbrcWfKT5fMUWYRAWr9NqCtvMRdGHPs7MgMeZVKXi7y0becbPHVtytxmi3juR2RyQ5QPDXZNtSlOAxOz04/7a+g809Q//n29brl9WaTWDw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ComprobanteAsociado = _t, ID = _t, Facha = _t, Vendedor_ID = _t, Tipo = _t, Product_ID = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ComprobanteAsociado", type text}, {"ID", Int64.Type}, {"Facha", type date}, {"Vendedor_ID", Int64.Type}, {"Tipo", type text}, {"Product_ID", Int64.Type}, {"Value", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Tipo"}, {{"all", each _, type table [ComprobanteAsociado=nullable text, ID=nullable number, Facha=nullable date, Vendedor_ID=nullable number, Tipo=nullable text, Product_ID=nullable number, Value=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddColumn([all], "NewColumn", each Record.FromList({[Value]},{[Tipo]}))),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"ComprobanteAsociado", "ID", "Facha", "Vendedor_ID", "Tipo", "Product_ID", "Value", "NewColumn"}, {"ComprobanteAsociado", "ID", "Facha", "Vendedor_ID", "Tipo", "Product_ID", "Value", "NewColumn"}),
    #"Expanded NewColumn" = Table.ExpandRecordColumn(#"Expanded Custom", "NewColumn", {"VEN","DEV","CAM"}, {"VEN","DEV","CAM"})
in
    #"Expanded NewColumn"

vkkfmsft_1-1658214659907.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@Syndicate_Admin , You can create new column like

 

ven Importe = if([Type] ="VEN" , [Importe], blank())

 

you can create new columns in the same manner

 

Also, you can consider pivot

https://radacad.com/pivot-and-unpivot-with-power-bi

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.