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

Weight Averages (Dax, Columns, something different?)

So I have what I need in excel as a mock-up

EricWR_0-1673638722428.png

Essentially, I have four categories and sometimes more across a project. There are some in a list so I am using the distinct function for what I have accomplished thus far. This list is important because I want to run my analysis on listed items only. 

The basic setup is, if its in list I need to multiply a ratio of what those listed prices are against the total sum. 
So the scenario above is that the Product C and D are 99% of the project, but the other 1% needs to be allocated against the other 99% in such a way that we respect the ratio of cost that Product C and D are to the Sum of Product C and D. So that way, I can take my remaining dollars of $6k and spread it against Product C and D. In the scenario above Product C would get $4,829 otherwise known as 80.48% and the Product D would get $1,171 otherwise known as 19.52%. The 80.48% and 19.52% are a sum of Product C and D cost and weighted. 




I know this is turning into a lot thus far but I will add what I have thus far. I know the numbers dont match but I was trying to make it more simple in my example. The first red arrow on the bottom is DAX that basically sums any cost if its in the list of products (the last two items are in the list, the first two are not). The number 2 red arrow is DAX that takes product cost minus the filtered list from the first. Red arrow 1 would give me give me the ratio of what these products are to the project when you add them together and then divide them against themselves, right now I have dollars. The second red arrow is the remaining cost not in the list, i.e. the remaining cost that needs to get built back into the first DAX results based on the first DAX results ratio.

 

EricWR_1-1673639304683.png

I have done the little that I could in DAX for the first Value Field in my matrix and its the cost of listed items which equal $2,822,469. The second Value Field in my matrix is also DAX and is basically the inverse, but it filters out what I need for my second group of ratios. The missing piece is getting the ratios of the first Field Values, to then multiply the total cost in the 2nd Field Value.

 

Basically equating to,

$2,815,236 (99.74% of Total Cost)

$7,233 (0.26% of Total Cost)

$2,822,469 (Total Project Cost of Listed Items)

 

Now we want to take the total of non-listed products $1,177,102 and spread it across the $2,822,469 by the two percentages we derived above, 99.74% and 0.26%.

 

So then the new cost of the first item would be

$2,815,236 + 1,174,085(99.74%)

and the new cost for the second item would be

$7,233 + $3,017(0.26%)

 

Now all cost have been accounted for and the non-listed cost has been weighted into the first cost.

 

Thank you to the Power BI gods for the help!!!



1 REPLY 1
DataInsights
Super User
Super User

@Anonymous,

 

Try this solution.

 

Data model:

 

DataInsights_0-1673718830749.png

 

Measures:

 

Total Cost = SUM ( FactTable[Cost] )
Total Cost with Allocation = 
// get total cost of all products
VAR vTotalCost =
    CALCULATE ( [Total Cost], ALL ( DimProduct ) )
// get total cost of filtered products
VAR vTotalFilteredCost =
    CALCULATE ( [Total Cost], ALLSELECTED ( DimProduct[Product ID] ) )
// get total cost of non-filtered products
VAR vTotalNonFilteredCost = vTotalCost - vTotalFilteredCost
// get ratio of each filtered product
VAR vTable =
    ADDCOLUMNS (
        VALUES ( DimProduct[Product ID] ),
        "@Ratio", DIVIDE ( [Total Cost], vTotalFilteredCost )
    )
// add allocated cost to actual cost
VAR vResult =
    SUMX ( vTable, [Total Cost] + ( vTotalNonFilteredCost * [@Ratio] ) )
RETURN
    vResult

 

Result:

 

DataInsights_1-1673718905493.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.