Calculation of all sold flowers in summer that are also sold in other seasons

Pivvv

New Member
Joined
Aug 25, 2014
Messages
10
I have an example salestable of flowers as shown below.
I'm trying to make a pivot table that shows all sales of flowers that are sold in summer, but that also shows the sales if these flowers are sold in other seasons as well.

The end result should be a pivot table that only shows the records with 1.000 sales.


fleyr6.png



My formula for the measure "SummerSales" is as follows:

SummerSales:=
CALCULATE(
SUM(Tbl_Sales[Sales]);
Tbl_Sales[Season]="Summer"
)

It already shows 4 of the 7 lines but the red ones are missing :(
How can i make this work?
I was trying to involve VALUES but I can't manage to make a VALUES formule for all Flowers with Season=Summer... Maybe this is not possible.
2wg6ffd.png
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
There seem to be a few ways of doing this...here's one:

Code:
=
CALCULATE (
    SUM ( Tbl_Sales[Sales] ),
[B]    CALCULATETABLE ([/B]
[B]        VALUES ( Tbl_Sales[Flower] ),[/B]
[B]        ALLEXCEPT ( Tbl_Sales, Tbl_Sales[Flower] ),[/B]
[B]        Tbl_Sales[Season] = "Summer"[/B]
[B]    )[/B]
)
The logic is to keep the current filter on Flower, but additionally filter Flower to only those that have been sold in Summer at least once.

The CALCULATETABLE does this by:

  1. Using ALLEXCEPT ( Tbl_Sales, Tbl_Sales[Flower] ) to remove all filters except keep existing filter on Flower
  2. Restricting Season to Summer using Tbl_Sales[Season] = "Summer"
  3. Then returning values of Flower remaining, which will only include Flower values in the current filter context which have ever sold in Summer.
 
Upvote 0
Tnx! It works perfectly (as shown below). You also say there are a few ways of doing this. I am really curious what other ways there are because this a great way for me to understand the more complex calclate formulas. I often have this scenario and until now I always solved it by filtering the pivot table on season=summer, then select all the Flowers and filter on those, and then removing the filter on Season. But this technique is sometimes to heavy for our SSAS server/too large pivot tables. So I am really interested in all possible ways of solving this scenario, especially for learning purposes, this would help me a lot!

dhe5i9.png
 
Upvote 0
Glad it works!

Here are a couple of others:

Code:
=
CALCULATE (
    SUM ( Tbl_Sales[Sales] ),
    CALCULATETABLE (
        VALUES ( Tbl_Sales[Flower] ),
        FILTER ( ALL ( Tbl_Sales ), Tbl_Sales[Season] = "Summer" )
    )
)


Code:
=
CALCULATE (
    SUM ( Tbl_Sales[Sales] ),
    FILTER (
        VALUES ( Tbl_Sales[Flower] ),
        CALCULATE (
            COUNTROWS ( Tbl_Sales ),
            ALLEXCEPT ( Tbl_Sales, Tbl_Sales[Flower] ),
            Tbl_Sales[Season] = "Summer"
        )
            > 0
    )
)
 
Upvote 0
Nice work Oz :)

I tend to sorta... build up my measures 1 step at a time, so my solution is either easier to understand, or harder... depending on how your brain works :)

Total Count:=COUNTROWS(Table1)
Count of Avail in Summer:=CALCULATE([Total Count], Table1[Season] = "Summer")
Total Sales:=SUM(Table1[Sales])
Sales of Avail in Summer:=CALCULATE([Total Sales], FILTER(VALUES(Table1[Flower]), [Count of Avail in Summer] > 0))

Which is very much like Oz's last measure.
 
Upvote 0
Tnx a lot!! All tested and they all work, also yours scottsen. But the first one of Ozeroth is definitly the most performant which I definitly need as i'm running a 32-bit laptop with 4 GB's RAM :') and I'm not able to add more than 2 rowlabels in my pivot table. Even when importing only the necessary columns = 5 columns and 1 measure :)

I'm going to analyze these formula's in the weekend as I need to understand how they work to benefit more from it in the future.
I'm like a lonely knight in a 5.000 employee company right now :')
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top