Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Sum a column using filters relating to a distinct value in another column

I have a table containing columns for passengers, passenger class, ticket no. and cost of ticket. However, where the ticket is for more than one passenger the total cost of the ticket has been included for each passenger as per the sample table

PassengerTicketClassCost
1A1A20
2A2A21
3A3A39
4A3A39
5A4B15
6A5B42
7A5B42
8A5B42
9A6C10
10A7C9

 

I am trying to find the average ticket price per class so need to filter the cost column by class and just sum the first occurrence of the cost per ticket (I can't sum the first occurrence of the cost as in my actual table some ticket costs are the same for other tickets).

I can use FILTER to seperate the class but I can't work out how to include only one value per ticket. 

 

I have tried so many versions to sum up the cost column correctly this being my last attempt - 

TEST  = Calculate(SUMX('Sample','Sample'[Cost]),DISTINCT('Sample'[Ticket]),FILTER('Sample','Sample'[Class] = "A"))
but it returns the equivalent of 119 from the table above rather than 89.
 
Can someone help please?
1 ACCEPTED SOLUTION

Hi, @Anonymous Substituted the data you provided, review the file to see if this is your desired result


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

View solution in original post

13 REPLIES 13
Anonymous
Not applicable

Can you just advise how you filtered by class. That is the right sum for Class As but how do I get the same for B and C?

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_0-1666964989717.png

 

 

Cost total distinct: =
SUMX ( DISTINCT ( Data[Ticket] ), CALCULATE ( MAX ( Data[Cost] ) ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Sorry Jihwan_Kim but what I ultimately need is 

A - 80 / 4 = 20

B - 57 / 4 = 14.25

C - 19 / 2 = 9.5

 

 

@Anonymous try it
Screenshot_10.jpg


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
Anonymous
Not applicable

That's the correct sums per Class for my sample table so I'm just going to try it on my actual table and will get back to you.

Anonymous
Not applicable

I've just tried it on my actual table and it has returned just one result which I believe is the average for the last class (equivalent to Class C). 

@Anonymous provide example data please to understand the calculation


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
Anonymous
Not applicable

This is just a small sample of my data with all other irrelevant columns deleted but I think it includes examples of multiple and single passenger tickets across all classes. Incidently when I tried SUMX(SUMMARIZE('table','table'[Class],'table'[Cost]),[Cost]) it returned 

a too few arguments error so I'm not sure where I went wrong there either!

PassengerFareTicketClass
ABBING427.5555473rd Class Passenger
ABBOTT1320.2526733rd Class Passenger
ABBOTT1620.2526733rd Class Passenger
ABBOTT3520.2526733rd Class Passenger
ABELSETH167.133481253rd Class Passenger
ABELSETH257.133481223rd Class Passenger
ABELSON282433812nd Class Passenger
ABELSON302433812nd Class Passenger
ABI SA'B457.4626853rd Class Passenger
ABI SHADID197.4626983rd Class Passenger
ABRAHAMSSON197.18631012843rd Class Passenger
AKS189.353920913rd Class Passenger
AL-BA'QLINI219.258326663rd Class Passenger
AL-BA'QLINI2319.258326663rd Class Passenger
AL-BA'QLINI319.258326663rd Class Passenger
AL-BA'QLINI519.258326663rd Class Passenger
ALBIMONA2618.787526993rd Class Passenger
ALLISON0.92151.551137811st Class Passenger
ALLISON2151.551137811st Class Passenger
ALLISON25151.551137811st Class Passenger
ALLISON30151.551137811st Class Passenger
ALLUM188.322233rd Class Passenger
ANDERSSON177.92531012813rd Class Passenger
ANDERSSON267.1563470753rd Class Passenger
ANGLE31262268752nd Class Passenger
ANGLE36262268752nd Class Passenger
ASPLUND1331.38753470773rd Class Passenger
ASPLUND237.15113500543rd Class Passenger
ASPLUND331.38753470773rd Class Passenger
ASPLUND3831.38753470773rd Class Passenger
ASPLUND4031.38753470773rd Class Passenger
ASPLUND531.38753470773rd Class Passenger
ASPLUND631.38753470773rd Class Passenger
ASPLUND931.38753470773rd Class Passenger
ASSAM237.131013093rd Class Passenger
ASTOR18227.525177571st Class Passenger
ASTOR47227.525177571st Class Passenger
ATTALAH1714.458326273rd Class Passenger
ATTALAH307.22526943rd Class Passenger
AUBART2469.3174771st Class Passenger

Hi, @Anonymous Substituted the data you provided, review the file to see if this is your desired result


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
Anonymous
Not applicable

Thanks so much that works now. As a newbie I have not yet come across the more detailed formula you used. I need to do more studying!

@Anonymous I wish you success and a good experience, everything will be fine


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
Anonymous
Not applicable

Sorry that's '80' not '89'!

@Anonymous  try it
Screenshot_10.jpg


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.