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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Hugo62Glu
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? 

 

Thanks in advance for your help

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
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:

vjianbolimsft_0-1669624999288.png

vjianbolimsft_1-1669625010251.png

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.

View solution in original post

2 REPLIES 2
v-jianboli-msft
Community Support
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:

vjianbolimsft_0-1669624999288.png

vjianbolimsft_1-1669625010251.png

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.

Greg_Deckler
Super User
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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

Top Solution Authors