cancel
Showing results for
Did you mean:
New Member

## Create measure to calculate value of attributes

Hello everyone,

I want to create a P&L waterfall, from gross sales to gross margin. For this, I have a table which comprises ,a column for gross sales, a column for net sales, margin, a column for the year, column for product type and so on.  To create the visualisation I need, I am using an intermediate table, with the first column called "attributes" including gross sales, trade terms, promotions, net sales,COGS margin etc. Then, I will need to create 3 measures: value for the base (only value for gross sales, net sales and margin), a measure for calculating negative value (so only calculating the sum of trade terms, promotions and COGS), a measure which will be showed as transparent (little trick to set up a waterfall with a bar chart).

I was wondering how to create those 3 caculations based on the columns in my first table. For my first measure and if I were to use excel, it will be: if(attribute="gross sales", sum(gross sales), if(attribute="net sales", sum(net sales), if(attribute="gross margin", sum(gross margin),0). I want these measures to be linked to my first table in order to use slicers and the value will update.

However, I don't know how to create these 3 measures based on my attributes displayed as rows.

Would you have an idea on how I can do it?

1 ACCEPTED SOLUTION
Community Support

Hi @Hugo62Glu ,

You can use Switch() function to achiveve this goal.

Here is a simple example:

I created three simple measures, each of them is just the name of themselves.

Then create a new measure :

``````Measure =
SWITCH(SELECTEDVALUE('intermediate table'[attributes]),
"gross margin",[gross margin],
"gross sales",[gross sales],
"net sales",[net sales],0)``````

Final output:

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 REPLIES 2
Community Support

Hi @Hugo62Glu ,

You can use Switch() function to achiveve this goal.

Here is a simple example:

I created three simple measures, each of them is just the name of themselves.

Then create a new measure :

``````Measure =
SWITCH(SELECTEDVALUE('intermediate table'[attributes]),
"gross margin",[gross margin],
"gross sales",[gross sales],
"net sales",[net sales],0)``````

Final output:

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Super User

@Hugo62Glu Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.

@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Announcements

#### 2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

#### Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

#### 2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.

Top Solution Authors
Top Kudoed Authors