Skip to main content

Hello, I have an issue that is difficult to describe so I provide an example subset below:

 

The data looks something like this:

INDEX

(for reference)

YearEmployeePrimary SaleSale IDPrimary Sale IDQuantity

 

1

2017

Bob

N

B1B31022017BobNB2B3532017BobYB3B31542017BobNB4B31052017BobNB5B31062017AliceYA1A11572017AliceYA2A21082017AliceYA3A35

 

In this scenario, I need to be able to calculate SUMS for each [Primary Sale] (as indicated by the value Y) together with the corresponding non-primary sales and return one record per [Primary Sale] with the same values for the fields as the [Primary Sale] and a total.

For example, Bob only has one primary sale, but the total of all non-primary sales corresponding to that sale total to 50. Therefore, Bob would have one record with the [Sale ID] of B3 and a total of 50.Alice has three separate primary sales with no corresponding sales so there would be three records for her, each with the corresponding values of only her primary sales.

Alice, on the other hand, has three separate primary sales with no corresponding nested sales so there would be three records for her, each with the corresponding values of only her primary sales.

 

The result should look something like this:

 

INDEX

(for reference)

YearEmployeePrimary SaleSale IDPrimary Sale IDTotal Quantity

 

12017BobYB3B35022017AliceYA1A11532017AliceYA2A21042017AliceYA3A35

 

What calculation could I use to accomplish this type of nested aggregation?

 

I tried IF and CASE statements and even considered LOD expressions but nothing clicked.

 

Thanks for your input!

 

Sincerely,

-Anthony

3 answers
  1. Jul 27, 2017, 7:59 PM

    Hi Anthony,

     

    If Primary Sale ID is already in your data, can you just remove the Primary Sale and Sale ID dimensions from your Rows shelf?  From what I can tell, in what you want, Primary Sale will always be Y and Sale ID will always be the same as Primary Sale ID. So if you were to simply remove those from the view, Tableau would automatically aggregate based on Primary Sale ID.

     

    Michael

0/9000