Question Group list by last 2 months and count its distinct items

lanceKidd

New member
Joined
Mar 5, 2017
Messages
1
Programming Experience
Beginner
Hi to all. Good day. I want to group a list by last 2 months and count how many products are their in every month and also count distinct category for every product sold in each month



I have a list. It contains a class named ProductTransaction.

C#:
[LIST]
[*]List[COLOR=#008000]<[/COLOR]ProductTransaction[COLOR=#008000]>[/COLOR] productList [COLOR=#008000]=[/COLOR] [COLOR=#008000]new[/COLOR] List[COLOR=#008000]<[/COLOR]ProductTransaction[COLOR=#008000]>[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[*][COLOR=#2B91AF]class[/COLOR] ProductTransaction
[*][COLOR=#000000]{[/COLOR]
[*][COLOR=#2B91AF]string[/COLOR] product;
[*]DateTime date_sold;
[*][COLOR=#2B91AF]string[/COLOR]  category;
[*][COLOR=#000000]}
[LIST]
[*]productList.[URL="http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Add"][COLOR=#813400]Add[/COLOR][/URL][COLOR=#000000]([/COLOR][COLOR=#008000]new[/COLOR] ProductTransaction [COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]product[COLOR=#008000]=[/COLOR][COLOR=#A31515]"sword"[/COLOR], date_sold[COLOR=#008000]=[/COLOR]03[COLOR=#008000]/[/COLOR]05[COLOR=#008000]/[/COLOR][COLOR=#0000C0]2017[/COLOR],category[COLOR=#008000]=[/COLOR][COLOR=#A31515]"weapons"[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];
[*]productList.[URL="http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Add"][COLOR=#813400]Add[/COLOR][/URL][COLOR=#000000]([/COLOR][COLOR=#008000]new[/COLOR] ProductTransaction[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]product[COLOR=#008000]=[/COLOR][COLOR=#A31515]"sword2"[/COLOR], date_sold[COLOR=#008000]=[/COLOR]03[COLOR=#008000]/[/COLOR]01[COLOR=#008000]/[/COLOR][COLOR=#0000C0]2017[/COLOR],category[COLOR=#008000]=[/COLOR][COLOR=#A31515]"weapons"[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];
[*]productList.[URL="http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Add"][COLOR=#813400]Add[/COLOR][/URL][COLOR=#000000]([/COLOR][COLOR=#008000]new[/COLOR] ProductTransaction[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]product[COLOR=#008000]=[/COLOR][COLOR=#A31515]"potion"[/COLOR], date_sold[COLOR=#008000]=[/COLOR]02[COLOR=#008000]/[/COLOR]05[COLOR=#008000]/[/COLOR][COLOR=#0000C0]2017[/COLOR],category[COLOR=#008000]=[/COLOR][COLOR=#A31515]"life"[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];
[*]productList.[URL="http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Add"][COLOR=#813400]Add[/COLOR][/URL][COLOR=#000000]([/COLOR][COLOR=#008000]new[/COLOR] ProductTransaction[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]product[COLOR=#008000]=[/COLOR][COLOR=#A31515]"jacket"[/COLOR], date_sold[COLOR=#008000]=[/COLOR]02[COLOR=#008000]/[/COLOR]03[COLOR=#008000]/[/COLOR][COLOR=#0000C0]2017[/COLOR],category[COLOR=#008000]=[/COLOR][COLOR=#A31515]"clothing"[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];
[*]productList.[URL="http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Add"][COLOR=#813400]Add[/COLOR][/URL][COLOR=#000000]([/COLOR][COLOR=#008000]new[/COLOR] ProductTransaction[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]product[COLOR=#008000]=[/COLOR][COLOR=#A31515]"jacketofBear"[/COLOR], date_sold[COLOR=#008000]=[/COLOR]02[COLOR=#008000]/[/COLOR]01[COLOR=#008000]/[/COLOR][COLOR=#0000C0]2017[/COLOR],category[COLOR=#008000]=[/COLOR][COLOR=#A31515]"clothing"[/COLOR][COLOR=#000000]}[/COLOR][COLOR=#000000])[/COLOR];
[/LIST]
[/COLOR]
[/LIST]



I want to achieve a data like below.Please see attached image file

Month productCount categoryCount
March 2 1
February 3 2


Thank you and GodBless
 

Attachments

  • output.png
    output.png
    3.5 KB · Views: 47
Last edited:
Back
Top Bottom