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

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
Community Support

``````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``````

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

``````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``````

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
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.

Frequent Visitor

Hi @lbendlin - thanks for that!

Data set

 Week Category Main Other Quantity Value 1 A 1 0 2 1 1 B 0 1 3 2 1 B 0 1 4 3 1 C 0 1 5 4 2 A 1 0 6 5 2 B 0 1 7 6 2 C 0 1 8 7

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)

 Week Category Value Value/MainQuantity 1 B 5 2.5 1 C 4 2

Any guidance would be greatly appreciated!

Thanks!

Rich

Super User

something like this?

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

Frequent Visitor

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)``````

Rich

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.

#### Power BI Monthly Update - February 2024

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

#### 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.

Top Solution Authors
Top Kudoed Authors