Forum Discussion
Returns only first row with lookupvalue
The "Total Sales" column is the total sales for 2018 per customer which has been taken from another table (with LOOKUPVALUE).
My original table contains only sales per customer per specific product. Now, I would like to add to this table the total sales for a specific year, per customer, and this is the source of my issue... (that lookupvalue DAX returns multiple figures).
Here'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 |
- Jimmy8016 years ago
Community Champion
Hello 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 ExpandAllRowsIf 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 - Jimmy8016 years ago
Community Champion
Hello Laufer_Israel
have you been able to solve the problem with the replies given?
If so, 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
All the best
Jimmy