Forum Discussion

ericsara's avatar
ericsara
Helper I
3 years ago
Solved

Adding two variables results in error

Hoping this may be a generic issue and not reliant on data to solve. 

 

I have the following measure.

 

Measure =
VAR _OneWeekEndSelected = HASONEVALUE(Dates[WeekEnding])
VAR _SelectedWeekOffset = IF(_OneWeekEndSelected=TRUE,VALUES(Dates[WeekOffset]),99)
VAR _WeekOffsetNeeded = _SelectedWeekOffset -1

VAR _HoursWorked =  CALCULATE(SUM('Star Projects Timesheet Data'[Hours]),ALL(Dates),Dates[WeekOffset]=_WeekOffsetNeeded)
VAR _StdHours = CALCULATE(SUM('Std Hours (2)'[Std Hours]),ALL(Dates),Dates[WeekOffset]=_WeekOffsetNeeded)
VAR _Include = IF(_HoursWorked=0,FALSE(),TRUE())
VAR _IsContractor = IF(VALUES(Resources[Type])=1,TRUE(),FALSE())

VAR _ContractorHours = IF(_Include=TRUE() && _IsContractor=TRUE(),_HoursWorked,0)
VAR _NonContractor = IF(_Include=TRUE() && _IsContractor=FALSE(),_StdHours,0)

VAR _TotalHours = _ContractorHours + _NonContractor
 
If I return _ContractorHours I get exactly what I want for contractors
If I return _NonContractor I get exactly what I want for non-contractors
Both return in a format of Decimal.
 
If I add the two as done in _TotalHours and then in a filter, I select only contractors (as in multi-select), they add as expected. Same if I select non-contractors.  However, as soon as I select both a contractor and a non-contractor, I get an error. A table of multiple values was supplied where a single value was expected. 
 
Why am I getting this, and how do I stop it?
I am confused as all I am doing is adding two numbers together. 
 
Cheers, 
  • ericsara , This code seems to have a problem when having more than one selected value

     

    VAR _IsContractor = IF(Max(Resources[Type])=1,TRUE(),FALSE())

2 Replies

  • ericsara , This code seems to have a problem when having more than one selected value

     

    VAR _IsContractor = IF(Max(Resources[Type])=1,TRUE(),FALSE())

    • ericsara's avatar
      ericsara
      Helper I

      Thank you so much.  I spend hours trying to work this out. Your are a legend.