Skip to main content
cancel
Showing results for 
Search instead 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

Reply
richard_jackson
Frequent Visitor

Category-split value divided by a calculated constant

Hi there!

 

I have a fact table which includes sales values with various different categories which can be split into "Main Sales" and "Other Sales" groupings (i.e. Category 1-3 = "Main", 4-6 = "Other"). Each entry has "Quantity" and "Value"

 

The client wants to have the "Other Sales" values split by categories, but all divided by the quantity which is the sum of "Main" sales.

 

Value of Other Sales (by Category) / SUM("Quantity" of "Main Sales").

 

This then needs to be provided with a weekly slicer and a YTD value.

 

What would be the best way to do this?

 

Thanks!

 

Rich

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @richard_jackson ,

 

Please check the formula:

Column = 
var a = CALCULATE(SUM('Table'[Value]),FILTER(ALLEXCEPT('Table','Table'[Week],'Table'[Category]),'Table'[Main]=0))+0
var b = CALCULATE(SUM('Table'[Quantity]),FILTER(ALLEXCEPT('Table','Table'[Week]),'Table'[Main]=1))
return
a/b

vjaywmsft_0-1670231148749.png

 

 

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

5 REPLIES 5
v-jayw-msft
Community Support
Community Support

Hi @richard_jackson ,

 

Please check the formula:

Column = 
var a = CALCULATE(SUM('Table'[Value]),FILTER(ALLEXCEPT('Table','Table'[Week],'Table'[Category]),'Table'[Main]=0))+0
var b = CALCULATE(SUM('Table'[Quantity]),FILTER(ALLEXCEPT('Table','Table'[Week]),'Table'[Main]=1))
return
a/b

vjaywmsft_0-1670231148749.png

 

 

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
lbendlin
Super User
Super User

Sounds like a standard weighting pattern. Please provide sanitized sample data that fully covers your issue.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

 

Hi @lbendlin - thanks for that!

 

Data set

 

WeekCategoryMainOtherQuantityValue
1A1021
1B0132
1B0143
1C0154
2A1065
2B0176
2C0187

 

Expected outcome

Parameters

Week=1

OtherCategory=1 (i.e. OtherCategory=1 or "true", MainCategory=0 or "false")

MainQuantity=2 (i.e. the sum of Quantity for any values for that week where MainCategory=1)

 

WeekCategoryValueValue/MainQuantity
1B52.5
1C42

 

Any guidance would be greatly appreciated!

 

Thanks!

 

Rich

something like this?

lbendlin_0-1669500789650.png

You would also have to specify how the totals should be computed.

 

Hi there - thanks for that!

That formula doesn't appear to give the quantity values per week though?

ValuePerMain = 
var a = CALCULATE(SUM(Sheet1[Quantity]), REMOVEFILTERS('Sheet1'[Category]),'Sheet1'[Main]=1)
RETURN DIVIDE(SUM('Sheet1'[Value]),a,0)

 

richard_jackson_0-1669630495858.png

Any advice on this?
Rich

Helpful resources

Announcements
Fabric Community Conference

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.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

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