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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
aaronhowe
Frequent Visitor

Converting a rank/count/value apportionment formula from Excel to BI

I have a formula in Excel which takes a total cost value and apportions it against various grades, which are ranked.  The quantity of a particular ranking can vary by month and by factor (shown here as Colour) but the total value will be a set figure each month.  For example:

 

aaronhowe_0-1715180509778.png

Those formulas:

 

Ranking formula:		    COUNTIF($B$2:$B$10,"<="&B2)
Apportionment formula:		$F$1*(COUNTIF($B$2:$B$11,"<="&B2)/SUM(C$2:C$11))

 

 

I can't seem to translate this to BI however.  Essentially I need to 1) count the number of instances of a given grade in a single month/month end, 2) sum the count of (1)) for a given month, then divide 1) by 2).  It seems like it should be simple but I can't seem to get a grip on the formula flow in DAX and my brain is melting as a result.

 

If I have the following data:

 

Month End	Colour	Grade	COUNTIF	As %
31/12/2023	Blue	A	1	5%
31/12/2023	Blue	B	2	11%
31/12/2023	Blue	B	2	11%
31/12/2023	Blue	C	2	11%
31/12/2023	Red	    C	2	11%
31/12/2023	Yellow	D	1	5%
31/12/2023	Green	E	3	16%
31/12/2023	Orange	E	3	16%
31/12/2023	Purple	E	3	16%

 

 

Then  I'd like to be able to allocate 5% of the total costs against an A grade, ~21% against a B grade, ~21% against C, 5% against D and ~48% against E.

 

I can't seem to replicate the combination of COUNTIF, percentage over a set of criteria (grade and month end), and grouping those values.  Actual grouping in Power Query didn't help unfortunately.  Is there something more simple I'm missing here?

1 ACCEPTED SOLUTION

@aaronhowe 

created both for columns and measures

11.PNG

 

pls see the attachment below





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

Proud to be a Super User!




View solution in original post

7 REPLIES 7
aaronhowe
Frequent Visitor

Thank you @ryan_mayu, that worked.  I need to figure out now how to apply it per-site manager but I think I can do that, your assistance is really appreciated!

you are welcome





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

Proud to be a Super User!




ryan_mayu
Super User
Super User

@aaronhowe 

pls try this to create the ranking

ranking = countx(FILTER('Table','Table'[Value]<=EARLIER('Table'[Value])),'Table'[Value])
 
what's the output for appd formular?
 
 
 




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

Proud to be a Super User!




Hi @ryan_mayu, sorry for the delay in replying - unfortunately I'm only on this project part time.  The output of the Appd formula in "Value Appd" is just the sum of the cost involved divided over the percentage applied per grade weighting.

 

I'm getting an error in the EARLIER function that the parameter is not of the right type - I'm not sure what I should have been using there.  The table is named 'Combined Site Margin' and contains a few key fields: Site Manager (text field), Direct Cost (sum of costs for the site manager, decimal field), Grade (text field), Index (an integer listing A, B, C as 1, 2 3, etc) and Month End (date/calendar field).

 

If I'm using EARLIER I assume I should be using it for a numeric type, so using the Index field should have been okay but it's refusing to accept it?

@aaronhowe 

are you createing a column or a measure? pls try to create a column

 

how many tables do you have?

 

could you pls just add the output in the screenshot of the excel?





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

Proud to be a Super User!




Cleary I need more coffee @ryan_mayu as I was creating a measure.  I switched it to a column and got a result, albeit a strange one so I think I'm still not going the right way.

 

I'm not sure I understand the request re the excel file.  Data as shown:

aaronhowe_0-1715758833067.png

 

As formulas:

aaronhowe_1-1715758874503.png

 

@aaronhowe 

created both for columns and measures

11.PNG

 

pls see the attachment below





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

Proud to be a Super User!




Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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