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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Curious_PBI
Frequent Visitor

Cumulative percentage total based on negative or positive values of a measure

Hi everyone, hope you're well,

 

I am pretty new in DAX and I need some help on one of my projects.

 

My formulas:

 

#Sales Allocation =
DIVIDE([#vs Target Total $], [#SumVsTargetTotal]) -- my cumulated sum

 

#vs Target Total $ =
[#Total Sales] - [#TargetTotal] -- my difference between target and sales

 

#SumVsTargetTotal = CALCULATE(([#Total Sales] - [#TargetTotal]),ALLSELECTED(Target_All)) -- my first attempt to have the total sum of the measure #TargetTotal to be able to divide and obtain a cumulated sum

 

#SumVsTargetTotal+ = IF([#vs Target Total $]>=0, [#vs Target Total $], 0) -- cumulated attempt of positive values

 

#SumVsTargetTotal- = IF([#vs Target Total $]<0, [#vs Target Total $], 0) -- cumulated attempt of negativevalues

 

#Sales Allocation2 = IF([#vs Target Total $]>=0,
DIVIDE([#vs Target Total $], CALCULATE(([#SumVsTargetTotal+]),ALLSELECTED(Target_All))),
DIVIDE([#vs Target Total $], CALCULATE(([#SumVsTargetTotal-]),ALLSELECTED(Target_All)))) -- second attempt to obtain the expected result

 

Error Message when I try to use a calculate function with a filter on the value of my measure #vs Target Total $ to be able to have a cumulated sum of my measure #Sales Allocation: A function 'PLACEHOLDER' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

 

With the formula:

#Sales Allocation = CALCULATE(DIVIDE([#vs Target Total $], [#SumVsTargetTotal]), [#vs Target Total $])

 

Expected result: Have a cumulated sum of 100% for negative values of #vs Target Total $ and of 100% for positive values as well.

 

Observation:
- I can't use a sumx cause my values come from a measure and not a table column in this case.
- I can't use a calculate function with a filter

 

I tried many things over many days but I begin to think that's impossible to do, I hope I'm mistaken or I don't see another way around to be able to realize that. I read a lot of forum threads.

 

I join an excel example of a sample, but I can't share the real data sample.

 

Thank you for all your participation and answers.

Have a great day!

 

EDIT: apparently we can't attach an excel file here, do there is a capture of the file:

 

sample.PNG

2 REPLIES 2
Curious_PBI
Frequent Visitor

Hi @v-yinliw-msft,

I just tried but, if I'm not mistaken, it doesn't change the situation cause I'm not able to obtain my expected result:


@Curious_PBI wrote:

Expected result: Have a cumulated sum of 100% for negative values of #vs Target Total $ and of 100% for positive values as well.

With the formula: 

#Sales Allocation =
var _vsTarget = [#vs Target Total $]
var _SumVsTargetTotal = [#SumVsTargetTotal]
return
Calculate(DIVIDE(_vsTarget, _SumVsTargetTotal))

I didn't add a filter to the calculate function because of the error message when you try to use a filter that is already part of the calculation.

 

In order to realize my goal, I need to find a way to extract the total of the negative and positive values separately and then divide my difference between target and sales by that number. I tried creating two different measures to obtain the total by the sign of values (positive or negative) but It's not working.

 

Thanks anyway!

v-yinliw-msft
Community Support
Community Support

Hi @Curious_PBI ,

 

You can use var in place of the measure:

For example:

#Sales Allocation = 

var _# vs Target Total $ = [# vs Target Total $]

var _# SumVsTargetTotal = [#SumVsTargetTotal]

return

Calculate(...)

Hope this helps you.

 

Best Regards,

Community Support Team _Yinliw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.