cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

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

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.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.