Forum Discussion
Returns only first row with lookupvalue
Hello Laufer_Israel ,
Apply a grouping with the columns that have distinct values. (Code, Name, Total sales). Here an example
let
Source = #table
(
{"Code","Name","Product","Quantity","Total sales 2018"},
{
{"1","One","PP","2","220"}, {"1","One","SS","3","220"}, {"1","One","YY","4","220"}, {"1","One","MM","9","220"}, {"2","Two","PP","1","167"}, {"2","Two","SS","4","167"},
{"2","Two","YY","7","167"}, {"2","Two","MM","2","167"}, {"3","Three","PP","3","701"}, {"3","Three","SS","1","701"}, {"3","Three","YY","3","701"}, {"3","Three","MM","8","701"}
}
),
ChangeType = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Name", type text}, {"Product", type text}, {"Quantity", Int64.Type}, {"Total sales 2018", Int64.Type}}),
Group = Table.Group(ChangeType, {"Code", "Name", "Total sales 2018"}, {{"AllRows", each _, type table [Code=number, Name=text, Product=text, Quantity=number, Total sales 2018=number]}})
in
Group
Copy paste this code to the advanced editor to see how the solution works. You can apply it by copying a part of my code to your query, or I can help you to apply a custom function
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
Thank you Jimmy for your prompt comment.
Since the data in my question is only an example of my issue, your recomendation is'nt valid on this case.
Actually what I would like to do, is to add another column that will show only the first row from "Total sales 2018" for each customer and will leave the rest of the rows for each customer blank.\
Does it possible??
- Laufer_Israel6 years ago
Helper I
The right column it is what I am looking for.
Code Name Product Quantity Total sales 2018 Total sales 2018 1 One PP 2 220 220 1 One SS 3 220 1 One YY 4 220 1 One MM 9 220 2 Two PP 1 167 167 2 Two SS 4 167 2 Two YY 7 167 2 Two MM 2 167 3 Three PP 3 701 701 3 Three SS 1 701 3 Three YY 3 701 3 Three MM 8 701 - v-xicai6 years ago
Community Support
Hi Laufer_Israel ,
You can create columns like DAX below.
Rank = CALCULATE(COUNT(Table1[Code]),FILTER(Table1, Table1[Code]<=EARLIER(Table1[Code]))) Total sales 2018_New=IF([Rank]=1, [Total sales 2018], BLANK())Best Regards,
Amy
Community Support Team _ Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Jimmy8016 years ago
Community Champion
Hello Laufer_Israel
if you need to do this in Power Query, use this slightly changed query
let Source = #table ( {"Code","Name","Product","Quantity","Total sales 2018"}, { {"1","One","PP","2","220"}, {"1","One","SS","3","220"}, {"1","One","YY","4","220"}, {"1","One","MM","9","220"}, {"2","Two","PP","1","167"}, {"2","Two","SS","4","167"}, {"2","Two","YY","7","167"}, {"2","Two","MM","2","167"}, {"3","Three","PP","3","701"}, {"3","Three","SS","1","701"}, {"3","Three","YY","3","701"}, {"3","Three","MM","8","701"} } ), ChangeType = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Name", type text}, {"Product", type text}, {"Quantity", Int64.Type}, {"Total sales 2018", Int64.Type}}), Group = Table.Group(ChangeType, {"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", {"Code", "Name", "Product", "Quantity", "Total sales 2018", "Total Sales 2018 new"}, {"Code", "Name", "Product", "Quantity", "Total sales 2018", "Total Sales 2018 new"}) in ExpandAllRowsCopy paste this code to the advanced editor to see how the solution works
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- Laufer_Israel6 years ago
Helper I
Guys,
As I mentioned, the table I shared with you is only an example for my data. (it is not even close to how my data looks like...)
Unfortunatlly, due to confidential matter I can't share my data with you.
Back to your proposals, it isn't solve my issue..
v-xicai - your proposal dosen't solve it since the rank column returns totally diffrent figures, so the "1" in the second DAX is not relevant.
Jimmy801 - I'm totally confuse from your proposal. my Advances Editor shows diffrence figures since as I noted above, my data looks diffrence in comparison to my exaple..
Anyway, many thanks for your willing to assist with this frustrating issue.
Other thoughts??
- Anonymous4 years agoNot applicable
Hi Laufer_Israel ,
Are you able to this kind of lookup? I yes. May I know please what DAX did you use?
Thank you 🙂