Forum Discussion
How to add a column which counts up the repeating value in another column?
Argh, you snuck your post in while I was typing mine!
Yes, should be able to expand to include certain [Item No] values, but would be easier to work on the original dataset as per my other post just now.
Pete
Ok, lets do as suggested by you in your other post. I will take one of my files which is creating the error while uploading and leave in only the neccessary columns. What will be the best way to provide it to you?
- BA_Pete4 years ago
Super User
If you're happy for it to be public, I think you should be able to drag and drop it into a post on here. If that doesn't work, then you could share it from OneDrive/Google Docs/ DropBox and post the link here.
Pete
- Anonymous4 years agoNot applicable
Can you use that Pete?
Tell me please when you have downloaded it, so I can take it down again.
- BA_Pete4 years ago
Super User
Okay, downloaded. You can delete post.
I'll have a look later and let you know how I get on.
Pete
- Anonymous4 years agoNot applicable
Thank you very much.
- BA_Pete4 years ago
Super User
Okay, so the issue was a fairly simple one: you had some dates that were zeroes:
I've added a simple replace step at the start to negate this and tidied up the code overall. You'll need to add your source steps at the top (I think everything up to #"Gefilterte Zeilen"?) but should work perfectly now.
You'll notice that I put your column rename step right at the end of the query - I always recommend to do this so that if you want to change column names in the future it doesn't break your whole query.
let Source = yourSourceSteps, repDateZeroToNull = Table.ReplaceValue( yourLastSourceStep ,0,null,Replacer.ReplaceValue,{"Invoice date", "Planned start date", "Planned finish date"}), chgDateTypesToText = Table.TransformColumnTypes(repDateZeroToNull,{{"Invoice date", type text}, {"Planned start date", type text}, {"Planned finish date", type text}}), chgDateTypesToDate = Table.TransformColumnTypes(chgDateTypesToText,{{"Invoice date", type date}, {"Planned start date", type date}, {"Planned finish date", type date}}), addMonthList = Table.AddColumn(chgDateTypesToDate, "monthList", each if [Planned start date] = null or [Planned finish date] = null then null else List.Distinct( List.Transform( {Number.From([Planned start date]).. Number.From([Planned finish date])}, each Date.StartOfMonth(Date.From(_)) ) ) ), addSplitInvoiceValue = Table.AddColumn(addMonthList, "splitInvoiceValue", each if [monthList] = null then null else [Line amount local c] / List.Count([monthList])), expandMonthList = Table.ExpandListColumn(addSplitInvoiceValue, "monthList"), chgNewColTypes = Table.TransformColumnTypes(expandMonthList,{{"monthList", type date}, {"splitInvoiceValue", type number}}), renameCols = Table.RenameColumns(chgNewColTypes,{{"Line amount local c", "Net Invoiced Sales"}}) in renameColsRegarding limiting the item codes that the split is applied to, there's a couple of ways to go about this. It really depends whether you want the item code list hardcoded into the query, or whether you will want to easily add/remove item codes in future.
To hardcode, you would use this 'addMonthList' step:
addMonthList = Table.AddColumn(chgDateTypesToDate, "monthList", each if [Planned start date] = null or [Planned finish date] = null or not List.Contains({"630", "100", "620"}, [Item number]) then null else List.Distinct( List.Transform( {Number.From([Planned start date]).. Number.From([Planned finish date])}, each Date.StartOfMonth(Date.From(_)) ) ) ),To be able to more easily change the values in future, you can create a separate query which is just a list of [Item number] values to include, then replace the List.Contains section above like this:
//Change this: List.Contains({"630", "100", "620"}, [Item number]) //to this: List.Contains( nameOfYourListQuery , [Item number])Pete