Forum Discussion
Laufer_Israel
Helper I
6 years agoReturns only first row with lookupvalue
Hi all, I have a table as can be seen below and I would like to see only the first row for "Total sales 2018" column. It is important to note that "Total sales 2018" is a data which has been taken ...
Laufer_Israel
Helper I
6 years agoHere's another demonstration of my data:
| Taken from another table | ||||||
| Month | Code | Name | Product | Sales per product | Total sales 2018 | Solution needed |
| January | 1 | One | PP | 2 | 220 | 220 |
| January | 1 | One | SS | 3 | 220 | |
| January | 1 | One | YY | 4 | 220 | |
| January | 1 | One | MM | 9 | 220 | |
| January | 2 | Two | PP | 1 | 167 | 167 |
| January | 2 | Two | SS | 4 | 167 | |
| January | 2 | Two | YY | 7 | 167 | |
| January | 2 | Two | MM | 2 | 167 | |
| January | 3 | Three | PP | 3 | 701 | 701 |
| January | 3 | Three | SS | 1 | 701 | |
| January | 3 | Three | YY | 3 | 701 | |
| January | 3 | Three | MM | 8 | 701 | |
| February | 1 | One | PP | 2 | 220 | 220 |
| February | 1 | One | SS | 3 | 220 | |
| February | 1 | One | YY | 4 | 220 | |
| February | 1 | One | MM | 9 | 220 | |
| February | 2 | Two | PP | 1 | 167 | 167 |
| February | 2 | Two | SS | 4 | 167 | |
| February | 2 | Two | YY | 7 | 167 | |
| February | 2 | Two | MM | 2 | 167 | |
| February | 3 | Three | PP | 3 | 701 | 701 |
| February | 3 | Three | SS | 1 | 701 | |
| February | 3 | Three | YY | 3 | 701 | |
| February | 3 | Three | MM | 8 | 701 |
Jimmy801
Community Champion
6 years agoHello Laufer_Israel
i don't get the point. Its basically the same data, just that you added a column and renamed another. I slightly adapted my code, and that's it. But the concept is always the same
let
Source = #table
(
{"Month","Code","Name","Product","Sales per product","Total sales 2018"},
{
{"January","1","One","PP","2","220"}, {"January","1","One","SS","3","220"}, {"January","1","One","YY","4","220"}, {"January","1","One","MM","9","220"},
{"January","2","Two","PP","1","167"}, {"January","2","Two","SS","4","167"}, {"January","2","Two","YY","7","167"}, {"January","2","Two","MM","2","167"},
{"January","3","Three","PP","3","701"}, {"January","3","Three","SS","1","701"}, {"January","3","Three","YY","3","701"}, {"January","3","Three","MM","8","701"},
{"February","1","One","PP","2","220"}, {"February","1","One","SS","3","220"}, {"February","1","One","YY","4","220"}, {"February","1","One","MM","9","220"},
{"February","2","Two","PP","1","167"}, {"February","2","Two","SS","4","167"}, {"February","2","Two","YY","7","167"}, {"February","2","Two","MM","2","167"},
{"February","3","Three","PP","3","701"}, {"February","3","Three","SS","1","701"}, {"February","3","Three","YY","3","701"}, {"February","3","Three","MM","8","701"}
}
),
ChangeType = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Name", type text}, {"Product", type text}, {"Sales per product", Int64.Type}, {"Total sales 2018", Int64.Type}, {"Month", type text}}),
Group = Table.Group(ChangeType, {"Month", "Code", "Name", "Total sales 2018"}, {{"AllRows", each _, type table [Code=number, Name=text, Product=text, Quantity=number, Total sales 2018=number]}}),
AddIndex = Table.TransformColumns
(
Group,
{{"AllRows", each Table.AddIndexColumn(_,"Index",1 )}}
),
AddColumn = Table.TransformColumns
(
AddIndex,
{{"AllRows", each Table.AddColumn(_,"Total Sales 2018 new",(add)=> if add[Index]=1 then add[#"Total sales 2018"] else null )}}
),
DeleteOtherColumns = Table.SelectColumns(AddColumn,{"AllRows"}),
ExpandAllRows = Table.ExpandTableColumn(DeleteOtherColumns, "AllRows", { "Month", "Code","Name", "Product", "Sales per product", "Total sales 2018", "Total Sales 2018 new"}, {"Month", "Code","Name", "Product", "Sales per product", "Total sales 2018", "Total Sales 2018 new"})
in
ExpandAllRows
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy