How do I create a filter using just one field where the drop down list shows grouped items from the field in Amazon Quicksight? - amazon-quicksight

I need to make regional groups from a 'Company' field in Quicksight. How do you create a filter that will show grouped companies? For example Region 1, Region 2, Region 3, etc. Each of these groups when chosen in the filter will need to show a specific list of companies from the one field 'Company' based on the Region chosen.
I've tried creating separate parameters (Region 1, Region 2, etc.) with the appropriate companies under each one but I could not figure out how to use those in a filter. In short I need to group companies together so the groups can be chosen from a dropdown filter.

I was able to find the answer to my question from another site. I wanted to share.
I had to use the locate function to create my groups in a calculated field.
Syntax for Calculated field:
locate(expression, substring, start)
Looked something like this:
ifelse
(
locate('Hotel by Marriott',{Hotel Name}) > 0,
'Marriott',
locate('Homewood Suites Hotel A, Homewood Suites Hotel B ',{Hotel Name}) > 0,
'Homewood Suites',
locate('Home 2 Suites Hotel A,Home2 Suites Hotel B',{Hotel Name}) > 0,
'Home2 Suites',
'Other Brands'
)
Expression is the actual Name in the specific field called Hotel Name list all values for that group in single quotes separated by commas.
Substring is the Field reference (Hotel Name)
Start is the Group Name ('Marriott') you want to refer to it by.
Then create a parameter as String with Multiple Values. Save and create a control with Multiple Static values which is your list of Group Names as written in the calculated field.

Related

How to Select multiple related columns in add calculated fields in Quicksight parameter using ifelse?

I have a parameter 'type' in a table and it can have multiple values as follows -
human
chimpanzee
orangutan
I have 3 columns related to each type in the table -
human_avg_height, human_avg_weight, human_avg_lifespan
chimpanzee_avg_height, chimpanzee_avg_weight, chimpanzee_avg_lifespan
orangutan_avg_height, orangutan_avg_weight, orangutan_avg_lifespan
So if i select the type as human, the quicksight dashboard should only display the three columns -
human_avg_height, human_avg_weight, human_avg_lifespan
and should not display the following columns -
chimpanzee_avg_height, chimpanzee_avg_weight, chimpanzee_avg_lifespan
orangutan_avg_height, orangutan_avg_weight, orangutan_avg_lifespan
I created the parameter type and in the add calculated fields I am trying to use ifelse to select the columns based on the parameter selected as follows -
ifelse(${type}='human',{human_avg_height}, {human_avg_weight}, {human_avg_lifespan},{function})
I also tried -
ifelse(${type}='human',{{human_avg_height}, {human_avg_weight}, {human_avg_lifespan},{function}})
And -
ifelse(${type}='human',{human_avg_height, human_avg_weight, human_avg_lifespan},{function}})
But none of it is working. What am i doing wrong ?
One way to do this would be to use three different calculated fields, one for all the heights, one for weights and one for lifespan. The heights one would look like this:
ifelse(
${type}='human',{human_avg_height}, ifelse(
${type}='chimpanzee', { chimpanzee_avg_height}, ifelse(
${type}='orangutan',{ orangutan_avg_height},
NULL
)))
Make another calculated field for weights and lifespan and then add these calculated fields to your table, and filter by type.
To make it clear to the viewer what data is present, edit the Title of the visual to include the type:
${type} Data
You have to create one calculated field for each measure using the ifelse with the type to choose the correct vale, but is not necessary to create inner ifelse as skabo did, the if else syntax is ifelse(if, then [, if, then ...], else) so you can define the calculated fields as follows:
avg_height = ifelse(${type}='human', {human_avg_height}, ${type}='chimpanzee', {chimpanzee_avg_height},${type}='orangutan', {orangutan_avg_height}, NULL)
avg_weight = ifelse(${type}='human', {human_avg_weight}, ${type}='chimpanzee', {chimpanzee_avg_weight},${type}='orangutan', {orangutan_avg_weight}, NULL)
avg_lifespan = ifelse(${type}='human', {human_avg_lifespan}, ${type}='chimpanzee', {chimpanzee_avg_lifespan},${type}='orangutan', {orangutan_avg_lifespan}, NULL)
Then use those calculated fields in your visuals.

ClickHouse: how to enable performant queries against increasing user-defined attributes

I am designing a system that handles a large number of buried point event. An event record contains:
buried_point_id, for example: 1 means app_launch, 2 means user_register.
happened_at: the event timestamp.
user_id: the user identifier.
other attributes, including basic ones (phone_number, city, country) and user-defined ones (click_item_id, it literally can be any context information). PMs will add more and more user-defined attributes to the event record.
The query pattern is like:
SELECT COUNT(DISTINCT user_id) FROM buried_points WHERE buried_point_id = 1 AND city = 'San Francisco' AND click_item_id = 123;
Since my team invests heavily in ClickHouse, I want to leverage ClickHouse for the problem. I wonder if it is a good practice to use the experimental Map data type to store all attributes in a MAP-type column such as {city: San Francisco, click_item_id: 123, ...}, or any other recommendation? Thanks.

New Column or Measure for NAICS ID based on first two numbers

Use first two digits of Column to give a name to a new column.
I have a list of companies and their NAICS ID. I would like to filter these into a pie chart but I don't want the 90000 different names (just the general ex. Agriculture or Mining). I want to utilize the first two digits in for the column to identify its general name. I am trying to use the DAX expression Switch to get this started. Is there a filter to do this within PowerBI?
I haven't started yet since I am not sure if this is possible.
You could simply create a calculated column based off of the original NAICS code using the following:
FirstTwoDigitsOfNAICS :=
SWITCH (
TRUE (),
LEFT ( 'Table'[NAICSCode] ) = x, "Something",
LEFT ( 'Table'[NAICSCode] ) = y, "Something Else"
)
This DAX will simply pull the first two characters from the entire code.

PowerBI: Slicer to filter a table Only when more than 1 value is selected

I have a table with 5 categories and units displayed into 2 types, Actual and budget.
I want to filter this table. Only when 2 or more values are selected in the slicer. Something like this.
I though of adding a measure, but dont know how to work the if statement exactly.
Measure = IF(COUNTROWS(ALLSELECTED(Report[Shipment Group])) = 1, "Something which would not filter the units", SELECTEDVALUE(Report[Units], SUM(Report[Units])))
Not sure if this is correct approach.Would like to know if any other approach is possible. Any help would be helpful. Thank you in advance.
This is a bit of an odd request, but I think I have something that works.
First, you need to create a separate table for your slicer values (or else you can't control filtering how you want). You can hit the new table button and define it as follows:
Groups = VALUES(Report[Shipment Group])
Set your slicer to use Groups[Shipment Group] instead of Report[Shipment Group].
Define your new measure as follows:
Measure = IF(COUNTROWS(ALLSELECTED(Groups[Shipment Group])) = 1,
SUM(Report[Units]),
SUMX(FILTER(Report,
Report[Shipment Group] IN VALUES(Groups[Shipment Group])),
Report[Units]))
or equivalently
Measure = IF(COUNTROWS(ALLSELECTED(Groups[Shipment Group])) = 1,
SUM(Report[Units]),
CALCULATE(SUM(Report[Units]),
FILTER(Report,
Report[Shipment Group] IN VALUES(Groups[Shipment Group]))))
Note: Double check that Power BI has not automatically created a relationship between the Groups and Report tables. You don't want that.

Tableau - Filter Measure Based on Different Variables of the Same Dimension

I have the following dimensions: Patients and Collection Type (Blood or Tissue). Measure: Collections.
I am counting how many blood and tissue collections for each patient have been made.
Here is my table: Collections per Patient by Collection Type
Now I want to filter this table: I want to display only those Patients who have more then 2 Blood Collections and more then 2 Tissue Collections.
So, I want to see only Patient B, D, and E.
How can I do this?
There are a variety of ways you could accomplish your desired result. Probably one of the easier ways would be to unpivot your data such that 'blood collections' and 'tissue collections' are separate columns instead of one. I don't believe Tableau natively supports this while importing a data source currently; however, you can created two additional calculated fields to replicate an unpivot.
Blood Field:
IF [Collection_Type] = 'Blood'
THEN [Collection]
ELSE Null
END
Tissue Field:
IF [Collection_Type] = 'Tissue'
THEN [Collection]
ELSE Null
END
EDIT: Create a Calculated field that contains your desired condition for filtering, Ex.:
(SUM([Blood_field]) > 2 AND SUM([Tissue Field]) > 2)
Calculated field will evaluate to TRUE or FLASE. Filter for records for TRUE on this field

Resources