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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
BrianNeedsHelp
Helper III
Helper III

Sum only Values where another Column has Data

Harder than it looks:  I have this simple table like below:  I want to calculate how we're performing based on the goal in a Card.  So I need to Sum only the goal values where the Gross Adds column is not blank(GAs are in the past and Goals are for the whole month). In theory this should work, but it puts a total for all the months previous rather than what is selected in the slicer.  What's strange is if I replace [GAGoal] with [Gross Adds] in the measure below it correctly adds up the Gross Adds for the current month selected in the slicer.    

 

GoalTotalCurrent = VAR LastDaySelection =     LASTNONBLANK ( 'Calendar'[Calendar Date], [Gross Adds] )  VAR CurrentRange =     DATESBETWEEN ( 'Calendar'[Calendar Date], MIN ('Calendar'[Calendar Date] ), LastDaySelection )  RETURN     IF ( LastDaySelection >= MIN ( 'Calendar'[Calendar Date]),CALCULATE ( [GAGoal], CurrentRange ))

 

 I've tried things like this, but it results in blank:  

 

SumGoals = IF(SUMX('Subscriber Activity',[Gross Adds])<>Blank(),SUMX('Subscriber Activity',[GAGoal]))

 

So it shouldn't sum 1/8,1/9,or1/10

Date      Goal  Gross Adds   
1/1/202556
1/2/202575
1/3/202587
1/4/202577
1/5/202543
1/6/202532
1/7/202521
1/8/20255 
1/9/20255 
1/10/20255 
8 REPLIES 8
lbendlin
Super User
Super User

You seem to be using a calculated column.  Probably what you wanted to do was a measure.

 

lbendlin_0-1736386505705.png

 

@lbendlin Hi.  I'm using a measure.  [GAGoal] is a measure, so I have to use SUMX, so I tried your formula like this and get "A function placeholder has been used in a true/false expression...":  

 

var md=MAX('Calendar'[Calendar Date])
return CALCULATE(SUMX('Subscriber Activity',[GAGoal]),'Calendar'[Calendar Date]<=md,NOT isblank('Subscriber Activity'[Gross Adds]))

 

 I got the formula below to work in the rows.  It only shows the goal in each row where there is a corresponding entry in Gross Adds.  These add up to like 3,000. But the total at the bottom shows 93,000. ????  So when I put the measure in a card it shows the total of 93k instead of 3000.  What is going on?   

 

SumGoalslessThanDate = 
Var GAGoalCalc = CALCULATE([GAGoal])
Return
Calculate(Sumx('Calendar',GAGoalCalc),filter('Calendar','Calendar'[Calendar Date]<=LASTNONBLANK('Calendar'[Calendar Date],[Gross Adds])&& 'Calendar'[Calendar Date]>=min('Calendar'[Calendar Date])))

 


 

Not sure what is happening in the other parts of your data model.  But I can put the measure in a card just fine.

lbendlin_0-1736388485395.png

see attached

 

On your file Goal is a column whereas I have Goal as a measure.  Anyhow I'm getting this error when I use the formula you presented:   "A function placeholder has been used in a true/false expression...":  Any way around that?  Your PBIX does exactly what i need, I just don't know how to make it work in this model.  

I figured out that the total in the card  is coming from it  summing the total goal for each day that the amount appears in the the date.   7 * 13k.  Just don't know how to fix it?  Each row is correct, but it's the sum that's off. 

remember that in a table visual measures are calculated twice, once for the rows and once for the row total. You can choose "MAX"  for the aggregation, or use HASONEVALUE /  ISINSCOPE  to modify the measure behavior according to where you are in the visual.

I simplified the measure, and now the sum total is correct for the whole month.  But this isn't what I was wanting-Need to just add the numbers that are visible.  I don't think this works for a measure?  If you modify the PBIX to calculate GAGoal in a measure like [PreviousYearGrossAdds]/[PYGAsAll]*[LocQuota], you'Il see what I'm talking about. I've tried many different purmutations with all nearly the same result:  

GoalLessthanDate = IF([Gross Adds]<>Blank(),( [PYGA]/[PYALLGAs])*[LocQuota1])

I even used the exact same code that works here: Why Power BI totals might seem inaccurate - SQLBI     But they must be calculating on columns and not measures?  There would have to be a different approach to make this work.  Please help.   

If you modify the PBIX to calculate GAGoal in a measure like [PreviousYearGrossAdds]/[PYGAsAll]*[LocQuota], you'Il see what I'm talking about

Very much not recommended.  Especially for troubleshooting you don't want to nest measures. Write your business logic out verbatim.  Only reference measures if you are confident about the result and are willing to absorb the cost of the extra context transitions.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.