I have table1 that is using dataset-A. I grouped this table by date. I have other dataset B which contains total_qty column.
I have to sum this column (total_qty) and show the result in table1 under every group total.
Data set A columns:
Date
company_code
location_name
volumes
Data set B columns:
Date
Company_code
Total_Qty
How can I get Sum(total_qty) from dataset B into table1 under group total? Also, total_Qty should change as it is placed in group.
Thanks
If you don't need to SUM anything for DataSet B's Company_code, you can use a Lookup to get the value. You would need to match the date and Company_code from both tables.
=LookUp(CSTR(FIELDS!Company_code.VALUE) & "|" & CSTR(FIELDS!Date.VALUE),
CSTR(FIELDS!Company_code.VALUE) & "|" & CSTR(FIELDS!Date.VALUE),
,FIELDS!Total_Qty.VALUE, "DataSetB")
This will combine your company code and date fields into one string and lookup the same combination in DataSet B.
Related
Seeking assistance regarding how to structure a query that will be processing data from multiple sheets (ie tabs), however both sheets have different data structure.
The first query (below) queries a tab that contains all of my expenses itemised. This sums them by month.
=query(Expense_Data, "SELECT C, SUM(Q) where T Matches 'Expense' GROUP BY C ORDER BY C desc limit 3 label SUM(Q) 'Expenses'",1)
Example Data Output Below
Date
Expenses
01/01/2021
-$1000
01/02/2021
-$1500
01/03/2021
-$1000
What I am seeking is to query another sheet which contains data (located in column G) that I wish to return based upon the date returned from the first query (located in column A), which I will then calculate the difference between. My issue is associating the 2 data sets together. Any support would be greatly appreciated!
Date
Expenses
Budget
Difference
01/01/2021
-$1000
-$2000
-$XXXX
01/02/2021
-$1500
-$1500
-$XXXX
01/03/2021
-$1000
-$1500
-$XXXX
try:
=QUERY(Expense_Input,
"select C,sum(Q)
where T matches 'Expense'
group by C
order by C desc
limit 3
label sum(Q) 'Expenses', C'Month'
format C'mmmm yyyy'", 1)
then:
={"Budget"; ARRAYFORMULA(IFNA(VLOOKUP(TO_TEXT(A13:A),
{'Expense Lookup (Monthly)'!C:C&" "&'Expense Lookup (Monthly)'!D:D,
SUBSTITUTE('Expense Lookup (Monthly)'!G:G, "$", )*1}, 2, 0)))}
and:
={"Difference"; INDEX(IF(A13:A="",,C13:C-B13:B))}
update
in one go:
=ARRAYFORMULA(QUERY({QUERY(Expense_Input,
"select C,sum(Q)
where T matches 'Expense'
group by C
order by C desc
limit 3
format C 'mmmm yyyy'", 1), IFNA(VLOOKUP(TEXT(INDEX(QUERY(Expense_Input,
"select C,sum(Q)
where T matches 'Expense'
group by C
order by C desc
limit 3",1),,1), "mmmm yyyy"),
{'Expense Lookup (Monthly)'!C:C&" "&'Expense Lookup (Monthly)'!D:D,
SUBSTITUTE('Expense Lookup (Monthly)'!G:G, "$", )*1}, 2, 0))},
"select Col1,Col2,Col3,Col3-Col2
label Col1'Month',Col2'Expenses',Col3'Budget',Col3-Col2'Difference'"))
I would like to select from a partitioned table where the date is the highest date strictly below a given date d.
I can do the following:
d:2019.10.02;
{select from x where date = max date} select from t where date < d
where t is my partitioned table.
The issue with the above query is that it is very slow as it has to first load all the dates strictly older than d, and then taking the max date out of it.
To select all the dates that are earlier than your specified date you can use the select statement below:
select from t where date=max date where date<d
Where t is your partitioned table and d is your specified date.
If you just want to select from the max date in a date partitioned hdb
Lets assume that the max populated date partition less than 2019.08.20 is 2019.08.07
q)d:2019.08.20
q)select from t where date=max date where date<d
This is because the partition type is available as a variable once you load into a DB, (i.e,. date, month, int etc). This will be the .Q.pf variable.
select from table where date=(last .Q.pv where .Q.pv < d)
kdb+ stores a variable in memory which contains all the dates within your db.
select from telemetry where date=desc[date]1
Above where clause will sort this by largest ->smallest
Selecting index 1 will filter the max date out of your query (without first querying the entire dataset).
I am trying to create one spx which based upon my ID which is 1009 will move 9 columns data to new table:
The old table has 9 columns:
CD_Train
CD_Date
CD_Score
Notes_Train
Notes_Date
Notes_Score
Ann_Train
Ann_Date
Ann_Score
userid - common in both tables
ID - 1009 - only exists in this table
and my new table has:
TrainingID,
TrainingType,
Score,
Date,
Status,
userid
TrainingType will have 3 values: Notes, CD, Ann
and other fields like score will get data from notes_score and so on
and date will get data from notes_date,cd_date depending upon in which column cd training went
status will get value from Notes_Train, cd_train and so on
based upon this, I am lost how should I do it
I tried querying one sql of users table and tried to do the join but I am losing the ground how to fix it
No idea yet, how to fill your column trainingId but the rest can be done by applying some UNION ALL clauses:
INSERT INTO tbl2 (trainingType,Date,Score,Status,userid)
Select 'CD' , CD_date, CD_score, CD_Train, userid FROM tbl1 where CD_date>0
UNION ALL
SELECT 'Notes', Notes_Date, Notes_Score, Notes_Train, userid FROM tbl1 where Notes_date>0
UNION ALL
SELECT 'Ann', Ann_Date, Ann_Score, ANN_Train, userid
FROM tbl1 where Ann_date>0
I don't know as yet whether all columns are filled in each row. That is the reason for the where clauses which should filter out only those rows with relevant data in the three selected columns.
I have a column with dates for financial transactions. I'd like to group them by quarter for a pivot table report. Not quite sure how to do this.
Assuming your dates are in ColumnA with Row1 a data label: insert =if(month(A2)<10,if(month(A2)>6,"Q3",if(month(A2)>3,"Q2","Q1")),"Q4") in Row2 of a helper column and copy down. Then use the helper column for your pivot table.
This is the desired result I need to populate as a report, where xx is number of people.
I have a table which has fields like:
----------
table1
----------
id
state
year(as Quarter)
gender
I need to determine the count from id and populate as a report. The year is like 20081, 20082..20084 (in quarter).
I have created a dataset using this query:
SELECT STATE,GENDER,YEAR,COUNT(*)
FROM TABLE 1
GROUP BY STATE,GENDER,YEAR
From this query I could populate the result
ex: ca, m , 20081,3
ny, f , 20091,4
From the above query I could populate the count and using group by(row) state(in ssrs).
I need to group by (column). From the gender I get and by year.
How do I take the column gender and make it has Male and Female column?
Do I need to create multiple dataset like passing
where gender = 'M' or gender = 'F'
so that I could have two datasets, one for Male and One for Female? Otherwise, is there any way I could group from the Gender field just like pivot?
Should I populate result separately like creating multiple dataset for Male 2008, Female 2009 or is there any way I could group by with the single dataset using SSRS Matrix table and column grouping?
Should I resolve it at my Query level or is there any Features in SSRS which could solve this problem?
Any help would be appreciated.
Your SQL query looks good, but I would remove the quarter with a left statement:
select state, gender, left(year,4) as [Year], count(ID) as N
from table1
group by state, gender, left([year],4)
Then you have a classic case for a Matrix. Create a new report with the Report Wizard, choose "Matrix", then drag the fields across:
Rows: State
Columns: Year, Gender
Details: N
This should give you the required Matrix. Then replace the expression of the textbox with the Gender from
=Fields!gender.Value
to
=IIF(Fields!gender.Value="M", "Male", "Female")
Good luck.