Splunk Search

How to transpose CSV into separate columns

tskarthic
New Member

I have the below two csv files:

  1. ProductSales.csv
  2. RegionalSales.csv

ProductSales.csv


ProductId,Product_name,Price
DB-SG-G01,Mediocre Kingdoms,24.99
DC-SG-G02,Dream Crusher,39.99
FS-SG-G03,Final Sequel,24.99
WC-SH-G04,World of Cheese,24.99
WC-SH-T0,World of Cheese Tee,9.99
PZ-SG-G05,Puppies vs. Zombies,4.99
CU-PG-G06,Curling 2014,19.99
MB-AG-G07,Manganiello Bros.,39.99
MB-AG-T0,Manganiello Bros. Tee,9.99
FI-AG-G08,Orvil the Wolverine,39.99
BS-AG-G09,Benign Space Debris,24.99
SC-MG-G10,SIM Cubicle,19.99
WC-SH-A01,Holy Blade of Gouda,5.99
WC-SH-A02,Fire Resistance Suit of Provolone,3.99

RegionalSales.csv


ProductId,TimeStamp,Region,Quantity
DC-SG-G01,9/6/2017,GA,5
DC-SG-G01,9/5/2017,GA,3
DC-SG-G01,9/4/2017,GA,6
DC-SG-G01,9/3/2017,GA,2
DC-SG-G01,9/6/2017,GA,1
DC-SG-G01,9/6/2017,TX,4
DC-SG-G01,9/5/2017,TX,5
DC-SG-G01,9/3/2017,TX,6
DC-SG-G01,9/2/2017,TX,1
DC-SG-G01,9/2/2017,TX,2
DC-SG-G02,9/3/2017,GA,4
DC-SG-G02,9/4/2017,GA,3
DC-SG-G02,9/3/2017,GA,5
DC-SG-G02,9/3/2017,GA,7
DC-SG-G02,9/1/2017,GA,9
DC-SG-G02,9/3/2017,TX,2
DC-SG-G02,9/4/2017,TX,5
DC-SG-G02,9/3/2017,TX,7
DC-SG-G02,9/3/2017,TX,2
DC-SG-G02,9/1/2017,TX,1

Added RegionalSales.csv file using "Add Data" -> "Monitor" -> "Files&Directory" options and Created a lookup table and configure the automatic lookup for the ProductSales.csv file.

Now doing search for the latest regional sales using below query:

sourcetype="reg_sales_csv" | dedup ProductId, Region| stats latest(TimeStamp) as TimeStamp by ProductId, Region, Quantity| xyseries ProductId Region Quantity| table ProductId , TimeStamp , GA, TX | fillnull Quantity=NA

So the search output something like below:

alt text

But not able to take the fields from the lookup table(SalesDetails.csv).

Actually expecting the below kind of table.

alt text

Need to display ProductName, Price fields for each productId from the lookup table.

How to join these search result with the lookup table matching records and framing this kind of table?

0 Karma
1 Solution

somesoni2
Revered Legend

Try this

sourcetype="reg_sales_csv" | dedup ProductId, Region| stats latest(TimeStamp) as TimeStamp by ProductId, Region, Quantity| xyseries ProductId Region Quantity| table ProductId , TimeStamp , GA, TX | fillnull Quantity=NA | lookup ProductSales.csv ProductId OUTPUT Product_name as ProductName Price | table ProductId ProductName Price TimeStamp GA TX

View solution in original post

0 Karma

somesoni2
Revered Legend

Try this

sourcetype="reg_sales_csv" | dedup ProductId, Region| stats latest(TimeStamp) as TimeStamp by ProductId, Region, Quantity| xyseries ProductId Region Quantity| table ProductId , TimeStamp , GA, TX | fillnull Quantity=NA | lookup ProductSales.csv ProductId OUTPUT Product_name as ProductName Price | table ProductId ProductName Price TimeStamp GA TX
0 Karma

timpacl
Path Finder

Try:
[your search] | table *

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Agentic SOC Triage: Investigating Splunk ES Notables with MCP Server and a Local LLM

The Problem: Too Many Alerts, Too Little Context Security operations teams running Splunk Enterprise Security ...

All Work and No Play? Not at .conf26! Unwind at These Evening Events

Between hands-on technical sessions, keynote reveals, and diving into live architectures, .conf26 is packed ...

Join the Hackathon at .conf26 and build a No-Code AI agent

Join us for the AI Agent Buildathon, an in-person, three-hour hands-on Hackathon where you’ll use Splunk Agent ...