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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
wenniin
Regular Visitor

SUM formula in several column with condition

I have 6 columns:

 

                | p1          | p2          | p3          | p4          | p5          | cost       |  

               -------------------------------------------------------------------

ex1          | apple     | orange   | apple     | apple     | grape     | 500        |              

ex2          | apple     | orange   | grape     |               |               | 300        |

ex3          | apple     | orange   | orange   |               |               | 750        |

ex4          | apple     |               |                |               |               | 250        |

 

the result I expected: 

ex1= 1 apple, 1 orange, 1 grape

ex2= 1 apple, 1 orange, 1 grape

ex3= 1 apple, 1 orange

ex4= 1 apple

 

cost don't depend on anything.

I need to make a bar chart (for all 5 columns) to show how many each product appear, each product will be count as 1 in the same example no matter how much the product appears.

I already tried pivot and the result is exactly what I want BUT it multiply cost column and ruined everything.

 

is there any other way to do it? Sorry if this is a basic problem, I'm just a beginner in power BI. any suggestion will be appreciated

 

4 REPLIES 4
MFelix
Super User
Super User

Hi @wenniin,

 

If you want to make hte count of the products follow the steps:

 

  1. Unpivot p columns
  2. Remove blanks
  3. Create a bar chart add the fields like this:
    1. ex - Axis
    2. fruit - legend
    3. fruit - values - summarize option distinct count

Result should be as you want check below:

 

fruit.png

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



sorry for the late response, I actually have many column in my table but only taking a neccesary column for ask.

I need a 'year' column to make this:

 

Bar ChartBar Chart

 

 

 

 I need bar chart to show me the quantity of product (apple, orange, grape) in 5 column (p1-p5) for certain condition (the product only count as 1 even if it shows more than once in the same row)

 

I'm using p1-p5 as axis (but it only calculating p1 and it is my current problem) and -count of 'year'- as value

 

Sorry for my lack of description and everything, please tell me if you have another suggestions. thank you

Greg_Deckler
Super User
Super User

Perhaps you just need to use AVERAGE for your cost instead of SUM and then you would be good?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

sorry if my question is confusing, I don't need the calculation of cost. The one I need is a total of product (p1-p5), but with a certain condition: if the product appear more than 1 in a row, it will only count as 1.

 

I can get the result I want with pivot function but it multiplied my cost column so I can't use that function

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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