Using GROUP BY on a Dataset in VB.NET - vb.net

This should be simple but it's not working as intended
I have a flat text file that is imported to a Dataset table, I just need to count occurences of a UserDefined3 column so in SQL it would be
SELECT UserDefined3, COUNT(UserDefined3)
FROM MRDF
GROUP BY UserDefined3
but I'm not sure how to do this in VB.NET acting on a DataTable

Related

Write SQL from SAS

I have this code in SAS, I'm trying to write SQL equivalent. I have no experience in SAS.
data Fulls Fulls_Dupes;
set Fulls;
by name, coeff, week;
if rid = 0 and ^last.week then output Fulls_Dupes;
else output Fulls;
run;
I tried the following, but didn't produce the same output:
Select * from Fulls where rid = 0 groupby name,coeff,week
is my sql query correct ?
SQL does not have a concept of observation order. So there is no direct equivalent of the LAST. concept. If you have some variable that is monotonically increasing within the groups defined by distinct values of name, coeff, and week then you could select the observation that has the maximum value of that variable to find the observation that is the LAST.
So for example if you also had a variable named DAY that uniquely identified and ordered the observations in the same way as they exist in the FULLES dataset now then you could use the test DAY=MAX(DAY) to find the last observation. In PROC SQL you can use that test directly because SAS will automatically remerge the aggregate value back onto all of the detailed observations. In other SQL implementations you might need to add an extra query to get the max.
create table new_FULLES as
select * from FULLES
group by name, coeff, week
having day=max(day) or rid ne 0
;
SQL also does not have any concept of writing two datasets at once. But for this example since the two generated datasets are distinct and include all of the original observations you could generate the second from the first using EXCEPT.
So if you could build the new FULLS you could get FULLS_DUPES from the new FULLS and the old FULLS.
create table FULLS_DUPES as
select * from FULLES
except
select * from new_FULLES
;

Combine Rows but concatenate on a certain field in Excel Power Query or Microsoft SQL

I have brought a table from an Authority database into Excel via power query OBDC type, that includes fields like:
Date - various
Comments - mem_txt
Sequence - seq_num
The Comments field has a length restriction, and if a longer string is entered, it returns multiple rows with the Comments field being chopped into suitable lengths and the order returned in the Sequence field as per extract below. All other parts of the records are the same.
I want to collapse the rows based and concatenate the various Comments into a single entry. There is a date/time column just outside of the screen shot above that can be used to group the rows by (it is the same for the set of rows, but unique across the data set).
For example:
I did try bring the data in by a query connection, using the GROUP_CONCAT(Comments SEPARATOR ', ') and GROUP BY date, but that command isn't available in Microsoft Query.
Assuming the date/time column you refer to is named date_time, the M code would be:
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
#"Grouped Rows" = Table.Group(
Source,
{"date_time"},
{{"NewCol", each Text.Combine([mem_text])}}
)
in
#"Grouped Rows"
Amend the Source line as required.

SQL Server - collapsing multiple row values into one field

I'm trying to produce the result shown in the "Desired Results" section (in SQL Server 2016) in my screenshot below, where the objections associated with each borrower number are in one column delimited by commas instead of separate rows.
I don't want to restructure my database - I just want to display the results as requested for a customer report. Thanks
I was able to use the STRING_AGG function which I didn't know existed to produce the results I need.
SELECT ht.Hearings_CaseID, Borrower_Number, STRING_AGG(Objection,',') AS Objection
FROM Hearings_Test ht INNER JOIN
Hearings_Objections_Test hot on ht.Hearings_CaseID = hot.Hearings_CaseID
GROUP BY
ht.Hearings_CaseID, Borrower_Number

column sorting in named sets power pivot (MDX)

i need help sorting columns in named sets created in power pivot
-data source is just plain .txt files on sharepoint
for example i have named set
{([Measures].[Sum of broj_stavki_KKPPL]),
([Measures].[prosečan broj iskomisioniranih stavki KP i PL]),
([Measures].[procenat učinka komisionara na KP i PL])}
and i need formula to sort second column or even better if i can get multiple sort for all columns
i have tried to use function ORDER but as i'm new to MDX function i just can get it right

SSRS Putting field from executed Dataset as Parameter to Second Dataset

My issue is when executing a stored procedure in a DataSet (exec pStoredProcedure) and SSRS populates different Fields for me to use. I wish to make an additional query to one of these fields.
DataSet 1 is:
exec pInfos #SessionGUID=#SessionGUID
Dataset 2 is simply:
select * from myTable where infoHeader is #HeaderInfo
In this query, #HeaderInfo is my dataField from the first DataSet that is returned. Note that the tablix is expanding for the number of #HeaderInfo there happens to be.
What's a simple way to put this field in as the parameter and put the result onto a tablix? (note the tablix data source is dataset1).
Special thanks to TMNT2014 for his comment!
I found two answers to my own question:
The first is to use Lookup, in which I did
select * from myTable
I then did a Lookup as:
=Lookup(Field!Headerinfo, Field!infoHeader, Field!ResultValue, "myTable")
And the value is as I needed it. I also found that by navigating to parameters and adding your own, you can specify the default Values of that parameter (in parameter settings) and then select the Dataset -> Value Field. Although I didn't test this one, I thought I'd include it.
I found this hard to follow, plus I needed to run my lookup in the group of my first dataset which required more than one lookup field.
First I wasted a ton of time with parameters. Nothing worked. Finally, I just added the fields I needed as the lookupset parms to my dataset query;
DataSet1 query:
Select a.c1, a.c2, a.c3, rtrim(ltrim(a.4))+'-'+convert(varchar(12), a.5, 101) as LookupKey from myTable a
Next I added the same key to my second dataset.
DataSet2 query:
Select b.c1, rtrim(ltrim(b.2))+'-'+convert(varchar(12), b3, 101) as LookupKey from myTable b
Now my two datasets have equivalent lookup keys based on multiple fields. Maybe there is an easier way with Lookup and LookupSet, but I didn't see it offhand.
In the Group footer of DataSet 1 I created an expression in the Tablix
=Join(LookupSet(fields!LookupKey.Value, Fields!LookupKey.Value, Fields!Comments.Value, "Comments"), vbcrlf)
And giving the following results: