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
Anonymous
Not applicable

Display Calculated Measure Bins as Axis, Calculated Measure as Values

Team - 

 

I have a table of weekly data (ProductData) and I would like to display weighted profit for Product A by it's gap to Product B (sample data below):

 

CustomerProductPrice Per UnitProfitDollar SalesWeek
Customer AProduct A1.991.0050,000Week 1
Customer AProduct B1.891.5060,000Week 1
Customer BProduct A1.791.101,000,000Week 2
Customer BProduct B1.661.602,500,000Week 2

 

I am comparing the price of the two products based on user parameter selections - the parameter table calculation is as follows:

 

Parameters = 

var products = VALUES('ProductData'[Product])
return CROSSJOIN(
SELECTCOLUMNS(products,"Product 1", [Product]),
SELECTCOLUMNS(products,"Product 2", [Product])
)

 

After the user selects two different products - I have the below measure that calculates the price gap between the two products:

 

Prod1-Prod2 Gap =

var prod1 = CALCULATE(
SUM('ProductData'[Price Per Unit]),
TREATAS(VALUES(Parameters[Product 1]),'ProductData'[Product])
)
var prod2 = CALCULATE(
SUM('ProductData'[Price Per Unit]),
TREATAS(VALUES(Parameters[Product 2]),'ProductData'[Product])
)
return (prod1-prod2)/prod2
 
I want to treat each result as a separate observations and bin them in 5% intervals - using the below calculation:
 
Gap Bins =
VAR BinSize = 0.05
VAR Bin = INT('ProductData'[Prod1-Prod2 Gap] / BinSize) * BinSize
RETURN Bin
 
I then weigh the profit by dollars sales at each customer - using the below calculation
 
Weighted Profit =
SUMX('ProductData',('ProductData'[Profit]*'ProductData'[Dollar Sales])/'ProductData'[Dollar Sales])
 
I now want to display Weighted Profit by Gap Bins in a bar chart (example below) - the issue I am running into is that you cannot use a calculated measure as an axis.  I also fear that the Weighted Profit calculation will bring in Profit for both Product A and Product B when all I care about is Product A profit.
 
Capture.PNG
I am more versed in Tableau than Power BI so, I will appreciate any help that you could provide! 😅
3 REPLIES 3
v-diye-msft
Community Support
Community Support

Hi,

 

If you've fixed the issue on your own please kindly share your solution. if the above posts help, please kindly mark it as a solution to help others find it more quickly.thanks!

 

Community Support Team _ Dina Ye
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

Power BI does support the concept of binning. It is found under the context menu of a column and you choose Group. Then you can select the grouping type as Bin.

 

However, in your case, you might want to create a new table to serve as your axis using something like:

Table 2 = GENERATESERIES(0,100,.05)
 
Then you could use that as your axis and write your measure such that it grabs the MAX Value out of that table and then filters your data such that you are only returning things that fall into that each bin.

@ 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...
Anonymous
Not applicable

Thank you, @Greg_Deckler -

 

RE: "Then you could use that as your axis and write your measure such that it grabs the MAX Value out of that table and then filters your data such that you are only returning things that fall into that each bin."

 

What would be the syntax to reference the Prod1-Prod2 Gap measure results to the values in the disconnected series table?  Would I need to have a MIN/MAX for each line in the generated series?  Not sure I understand how to return values specific to each bin.

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.