SQL custom grouping expression based on the field value string Microsoft Visual Studio - sql

I am having a table in BIDS with three columns (e.g. Team, Product Name, Count).
For the Column Product name, I want to apply grouping, that will check for particular string "laptop" and sum all the Product Names containing string "laptop" under Laptops. Values in Product Name may vary, but there is a certain pattern like XX.Laptop.1, YY.Laptop.2 and mix of combinations to laptop.
I need something that will render full list, but add a group over Tablix Group with use of custom expression =IIF(Fields!Product_Name.Value)LIKE "laptop", "Laptops")
Please kindly advice. Thank you
Much thanks Alejandro! here is the result I got after applying your suggestion.
RESULT
I need two additional questions:
If there is a second group I would like to use for grouping - how to add it? (eg. desktops)
How to add a sumary value for the group? Shall it be done over exprerssion?
Thank you

Try using this expression for setting the group by Product Name and to show the Product Name in the respective cell.
=IIF(InStr(Fields!Product_Name.Value,"laptop") > 0,"Laptops",Fields!Product_Name.Value)
If for a specific row the Product Name contains laptop it will group on "Laptops" otherwise it will group by the Product Name value for that row.
UPDATE: If you want to check for another word to create an additional group you can use:
=Switch(
InStr(Fields!Product_Name.Value,"laptop") > 0,"Laptop",
InStr(Fields!Product_Name.Value,"desktop") > 0,"Desktop",
true,Fields!Product_Name.Value
)
Let me know if this helps.

Related

How to combine rows in BigQuery that share a similar name

i'm having trouble creating a query that'll group together responses from multiple rows that share a similar name and count the specific response record in them.
the datatable i currently have looks like this
test_control
values
test
selected
control
selected
test us
not selected
control us
selected
test mom
not selected
control mom
selected
what i'd like, is an output like the below that only counts the number of "selected" responses and groups together the rows that have either "control" or "test" in the name"
test_control
values
test
3
control
1
The query i have below is wrong as it doesn't give me an output of anything. The group by section is where im lost as i'm not sure how to do this. tried to google but couldn't seem to find anything. appreciate any help in advance!!!
SELECT distinct(test_control), values FROM `total_union`
where test_control="%test%" and values="selected"
group by test_control, values
use below
SELECT
REGEXP_EXTRACT(test_control, r'^(TEST|CONTROL) ') AS test_control,
COUNTIF(values = 'selected') AS values
FROM `total_union`
GROUP BY 1
As mentioned by #Mikhail Berlyant, you can use REGEX_EXTRACT to match the expression and COUNTIF to get the count of the total number of matching expressions according to the given condition. Try below code to get the expected output :
Code
SELECT
REGEXP_EXTRACT(test_control, r'^(test|control)') AS test_control,
COUNTIF(values = "selected") AS values
FROM `project.dataset.testvalues`
group by 1
Output

How to count Product ‘A-D’ without Null Value?

When I was trying to create a dashboard in Qlikview, I write a statement to show up the following product data in a bar chat:
As you can see in the pic, however, the is a null value product to be counted.
I write the following statement in the Expression of Qlikview BarChart:
Count({<PRODUCT={'Enoxaparin Sodium','Insulin Glargine 300','Non-Promotional','Sevelamer Carbonate'}>}DISTINCT CALLID).
It can display what I want to see, but some other product may be missing in the future counting.
Who can tell me how to write an expression to count all the product without couting Null Value in Product Field?
I input like this Count({<PRODUCT={'<>NULL'}>}DISTINCT CALLID), but it didn't work.
I have resolved this problem by doing this:
count(distinct if(Not IsNull(PRODUCT),CallId))

SSRS 2008 R2 - How to aggregate group data based on inner group filters?

I have made a simplified example to illustrate the question i'm trying to ask here. In my example i have sales orders and each sales order has multiple lines, i group by Sales Order Number, then by Sales Order Line (row groups)
I have found Group Filters very useful/flexible in filtering report data in specific areas of a table, so in my example i filter the SOLine group to exclude the SO line if it equals 3.
Then, i want to have a group aggregate for the entire SO, to tell me a count of the SO lines within it. Unfortunately when doing COUNT() expression from a textbox within the Sales Order Number group scope it counts all the lines, including the SO Line 3, whereas i want it to take into consideration the line filtered out from its child group.
Below is a screenshot of my tablix and grouping:
On the SOLine group i have the following filter:
And below is the output i get when previewing the report:
I want that count to evaluate to 4, but i ideally want to keep using groups as i've found they are much more efficient than using SUM(IIF) which completely slowed down my actual report which has thousands of rows.
If this is not possible, please give all best alternatives i could use.
Many thanks.
Jacob

Percent of Group, not total

It seems like there are a lot of answers out there but I can't seem to relate it to my specific issue. I want to get the breakdown of yes/no for the specific Group. Not get the percent of the yes for the entire population of data.
I have tried the following code in the "What I'm Getting" % of Total cell =
=FormatPercent(Count(Fields!SessionID.Value)/Count((Fields!SessionID.Value), "Tablix1"),)
=FormatPercent(Count(Fields!Value.Value)/Count((Fields!SessionID.Value), "Value"),)
It should just be a case of changing the Scope in your expression to make sure the denominator is the total for the group, not the entire Dataset or Tablix, i.e. something like:
=Count(Fields!SessionID.Value) / Count(Fields!SessionID.Value, "MyGroup")
Where MyGroup is the name of the group, i.e. something like:
If this is still not clear, your best option would be to add a few sample rows, and your desired result for these, to the question so we can replicate your exact issue.
Edit after more info added
Thanks for adding more details. I have created a Dataset based on your example:
And I've created a table based on this:
The group is based on the Group field:
The Group % expression is:
=Fields!YesNoCount.Value / Sum(Fields!YesNoCount.Value, "MyGroup")
This is taking the YesNoCount value of each row and comparing it to the total YesNoCount value in that particular group (i.e. the MyGroup scope).
Note that I'm using Sum here, not Count as in your example expression - that seems to be the appropriate aggregate for your data and the required value.
Results look OK to me:

QlikView:Using dimensions value in expression

I am trying to figure out how can I use dimension values as one of the set modifiers in Expressions in qlikview. Consider the following:
Raw Data:
PName, count
AB,2
BC,3
CD,4
Dimension:
Name
Expression:
SUM(<{PName=Name}>count)
i-e using the dimension value as one of the set modifiers.
Thanks
As #bdiamante said. It is not clear what you exactly want to do.
But I assume that you only want to use the current value of the dimension to calculate the count of names.
If that is true, then you can simply say:
Expression:
=sum(count)
HTH
I believe I understand. Try sum({<Pname=p(Name)>}count). This says that pname will be the possible values of name. Also look into e() which is the excluded values.
If Name is a literal value, try this:
sum({<PName={'AB'}>}count)
It would always give you the count as if someone had selected PName = 'AB'.
If you only want it to show the count for AB, if AB has not been excluded based on the current selections (e.g. someone has selected PName of 'BC'), then use:
sum({<PName*={'AB'}>}count)
This will give you the count for AB, but only if AB is included in scope for (i.e. intersects with) the current selections.