Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

SumIf calculation and grouping by dimensions

buldozek
5 - Atom

Hello,

 

here is the sample data:

 

Shipping methodYearCountryQuantity
Plane2022Albania33
Plane2020Bulgaria45
Train2022Greece34
Train2021Greece20
Car2021Germany3

 

I would like to calculate the following: sum of quantity IF the shipping method is Plane, minus sum of quantity IF the  shipping method is Train. Then I'd like to group the results per Year, Country etc. so I would like to get these results by specific dimension, for Year 2022, 2021 etc

How to achieve something like this?

 

5 REPLIES 5
Luke_C
17 - Castor
17 - Castor

Hi @buldozek 

 

No countries have different shipping methods, so wouldn't the numbers just be the same as what you have? What does your expected output look like

buldozek
5 - Atom

Sumif(shipping method = 'Plane' - 78) - Sumif*shipping method = 'Train' - 54) = the result is 24 (for the whole dataset). Now I'd like to distribute this number among each Year and Country. So I'd like to do the same calculation but within specific Year.Hope this clarifies :)

messi007
15 - Aurora
15 - Aurora

@buldozek,

 

Please see below :

Hope this solve the problem if not please share with us what you expect to have :)

messi007_0-1650523985221.png

Attached the workflow,

Regards,

LogoPrime.png

 

JeroenJacobs
7 - Meteor

With a formula tool, select the Quantity field and make the following calculation;

IF [Shipping method]='Plane' THEN [Quantity] ELSEIF [Shipping method]='Train' THEN -[Quantity] ELSE 0 ENDIF

Next to that, make a summarize tool, group by Country and Year, and Sum Quantity.

Done :-)

buldozek
5 - Atom

Hi, @messi007 

 

this doesn't solve the problem. Let's say I want to get (3) subsets of my data filtering only 2020, 2021, 2022. Then I'd like to do this calculation. So for 2022 the result would be 33-34, for 2020 45 - 0 (there isn't any Train in shipping method for 2020) etc

Labels
Top Solution Authors