Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:34:34+00:00 2026-06-14T14:34:34+00:00

I have defined a record type for some client data in F# as follows:-

  • 0

I have defined a record type for some client data in F# as follows:-

  type DataPoint = {
       date: string; 
       dr: string; 
       Group: string; 
       Product: string; 
       Book: int; 
       Revenue: int} with 
          static member fromFile file =
               file
               |> File.ReadLines
               |> Seq.skip 1 //skip the header
               |> Seq.map (fun s-> s.Split ',') // split each line into array
               |> Seq.map (fun a -> {date = string a.[0]; dr = string a.[1];
                              Group = string a.[2]; Product = string a.[3];
                                Book = int a.[4]; Revenue = int a.[5] });;  

    // creates a record for each line
    let pivot (file) = DataPoint.fromFile file
              |> ??????????

For the rows where date, dr, Group and Product are all equal, I want to then sum all of the Book and Revenue entries, producing a pivoted row. So some kind of if else statement should be fine. I suspect I need to start at the first data point and recursively add each matching row and then delete the matching row to avoid duplicates in the output.

Once I have done this I will be easily able to write these pivoted rows to another csv file.

Can anyone get me started?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:34:36+00:00Added an answer on June 14, 2026 at 2:34 pm

    Seq.groupBy and Seq.reduce are what you’re looking for:

    let pivot file = 
        DataPoint.fromFile file
        |> Seq.groupBy (fun dp -> dp.date, dp.dr, dp.Group, dp.Product)
        |> Seq.map (snd >> Seq.reduce (fun acc dp -> 
                              { date = acc.date; dr = acc.dr; 
                                Group = acc.Group; Product = acc.Product;
                                Book = acc.Book + dp.Book; 
                                Revenue = acc.Revenue + dp.Revenue; }))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have some data types defined in PL/SQL: TYPE foo_t IS RECORD (...);
I have defined a table type PL/SQL variable and added some data there. create
Alright, I have some data that I need to assign an int type identifier
I have a parent/child/grandchild type table relationship defined as follows: tableA: parentID description tableB:
In my package, I have defined a record type and a corresponding table type.
I have defined a TCGTable record type with the following structure: type TCGTable =
I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid
How can I use some OCaml record that I've defined in some other file?
I have a records of types type tradeLeg = { id : int ;
To save the memory, I defined some record-like structs and stored their instances in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.