BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vietlinh12hoa
Obsidian | Level 7

Hi everyone,

I have the input table:

IDLow LevelHigh LevelCost
A0123
A1023
B1042
B0142
C0012
C1012
D005


meaning that an ID can be in both Level.

What I would like to do is to have a drop down selection for Level.

 

If I select Low Level. Only low level average cost display (average cost = (23 + 42 + 12) / 3 =25.7, and there are 3 unique IDs

Only Low Level

(Low Level = 1 and High Level = 0)

Average CostNumber of ID
25,73

 

If I select High Level. Only high level average cost display (average cost = (23 + 42) / 2 =32.5, and there are 2 unique IDs

Only High Level

(Low Level = 0  and High Level =1)

Average CostNumber of ID
32,52

 

As default (no selection), it will take into account all level with unique ID. (average cost = (23 + 42 +12 + 5) / 2 =20.5, and all unique IDs are counted.

All (Unique ID)
Average CostNumber of ID
20,54

 

How can we do that for this drop down aggregation?

1 ACCEPTED SOLUTION

Accepted Solutions
Sam_SAS
SAS Employee

So with that change and using a drop-down control we get this:

 

communitytableno1.gif

communitytablelow1.gif

communitytablehigh1.gif

View solution in original post

10 REPLIES 10
Sam_SAS
SAS Employee

Hello,

 

Would it make sense to create a calculated column "Level" with an expression like this?

IF ( ( 'High Level'n = 1 ) AND ( 'Low Level'n = 0 ) )
RETURN 'High Level'
ELSE (
IF ( ( 'Low Level'n = 1) AND ( 'High Level'n = 0 ) )
RETURN 'Low Level'
ELSE 'Neither' )

Then you could assign this Level column to a button bar control.

 

I think that would achieve the result that you are looking for. An extra clause might be needed to handle a "Both" case where both values are 1. I don't know if that is possible in your data.

 

Let us know if that helps,

Sam

vietlinh12hoa
Obsidian | Level 7

Thanks for the answers. Ideally, an ID can't be either High or Low. So you mean now we have 4 drop down selection for Level Column ('HIgh', 'Low', 'Neither', ' ' ) (Empty blank for all).

But I wonder the rule for aggregation in VIYA will be a little bit different when when no selection (All is considered). 

Sam_SAS
SAS Employee
I think that the expression I gave above should work. You will have a button bar like this:

[[High Level] [Low Level] [Neither]]

If the user does not make a selection on the button bar, then all values of the column will be displayed. There is no need for an additional "All" value in the calculated column.

Sam
vietlinh12hoa
Obsidian | Level 7
I see. but when there is no selection, the table should only display unique values, as seen in the last table only 4 unique IDs are aggregated.
Sam_SAS
SAS Employee

I am getting this output using your data:

 

communitytablelow.gif

communitytablehigh.gif

communitytablenoselectoin.gif

 

I calculated the distinct count for ID. To eliminate "Neither" from the button bar, I just created a filter on the button bar to remove that value.

 

The Cost value when nothing is selected is the average for the full data set, rather than the average of the averages for the ID. I believe there is a workaround for this if you want the value to be aggregated that way, but I don't remember how to do it.

 

You could also use a drop-down list control instead of a button bar. When there are only two selections, I like button bars.

 

Is this closer to what you wanted? 

 

Thanks,
Sam

 

Sam_SAS
SAS Employee

Replacing Cost with this calculation will give you 20.5:

AggregateTable(_Avg_, Table(_Avg_, Fixed('ID'n), 'Cost'n))

Sam_SAS
SAS Employee

So with that change and using a drop-down control we get this:

 

communitytableno1.gif

communitytablelow1.gif

communitytablehigh1.gif

vietlinh12hoa
Obsidian | Level 7
That's great thank you very much for your help
vietlinh12hoa
Obsidian | Level 7
Thank you very much. It works well.
Sam_SAS
SAS Employee
Excellent! Thanks for letting us know

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 1893 views
  • 11 likes
  • 2 in conversation