Author Topic: Can we pivot text value instead of sum or count in pivot  (Read 436 times)

vijay@spinetechnologies

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 87
    • View Profile
Can we pivot text value instead of sum or count in pivot
« on: May 23, 2023, 07:41:17 pm »
Can we pivot text value instead of sum or count in pivot

Please find attach file expected result.png

Source data and expected result are mention in that.



paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Can we pivot text value instead of sum or count in pivot
« Reply #1 on: May 24, 2023, 06:10:42 pm »
can you please share sample data so that I check its feasibility.

vijay@spinetechnologies

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 87
    • View Profile
Re: Can we pivot text value instead of sum or count in pivot
« Reply #2 on: May 24, 2023, 06:54:58 pm »
please find the attached text file which contains JSON data

vijay@spinetechnologies

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 87
    • View Profile
Re: Can we pivot text value instead of sum or count in pivot
« Reply #3 on: May 24, 2023, 07:08:57 pm »
as in previous file date was not in proper format

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Can we pivot text value instead of sum or count in pivot
« Reply #4 on: May 25, 2023, 04:44:26 pm »
Thanks for the JSON data. Yes, it works.

First define custom aggregate, you can name it anything.

Code: [Select]
pq.aggregate.custom = function( arr ){
return arr[ 0 ];
}

Then use that custom aggregate in groupModel:
Code: [Select]
var groupModel = {           
on: true, //grouping mode.
pivot: true, //pivotMode
titleIndx: 'Employee Name',
groupCols: ['Date'], //grouping along column axis.
agg:{ //aggregate fields.
DayType: 'custom'
},
header: false, //hide grouping toolbar.
dataIndx: ["Employee Name"], //grouping along row axis.
summaryEdit: false
};