Forum Discussion

MojoGene's avatar
MojoGene
Post Patron
9 years ago

Divide by YEARFRAC syntax

I can't seem to get the syntax correct on what appears to be a simple measure.

 

I have a measure that returns the current number of hours that have been billed and paid for the current year, [Hours Paid]. I want to use that number to determine the projected number of hours paid for the current year. Mathematically, this is [Hours Paid] divided by YEARFRAC.

 

Here is the measure that is returning incorrect results:

 

Hours Paid Projected for Year = DIVIDE([Hours Paid],YEARFRAC(STARTOFYEAR(Table_ExtendedCalendar[DateKey]), TODAY(),3))

When I divide [Hours Paid] by 1, I get the correct number of paid hours, so it looks like I am not stating the denominator correctly.

 

Thanks for any help.

5 Replies

  • The syntax written for your measure is not a valid syntax. You are trying to divide the measure by the column values.

     

    For such types of calculations, you need to use SUMX function.

     

    Create YEARFRAC Column in your table first.

     

     

    Yearfrac cal= YEARFRAC(STARTOFYEAR(Table_ExtendedCalendar[DateKey],TODAY(),3))

     

    Hours Paid Projected for year:=SUMX('TABLE NAME', Table Name[hours column]/Table Name[Yearfrac cal])

     

    Note:

    1. In SUMX calculation, columns are used for division and not measures.

    2. Make sure, you have correct data types set up for your columns.

     

    Thanks & Regards,

    Bhavesh

    • MojoGene's avatar
      MojoGene
      Post Patron

      Bhavesh:

       

      Thanks for your reply. When I try that, I get the result "NaN" (not a number).

       

      Any further advice on what i might be doing wrong?

      • BhaveshPatel's avatar
        BhaveshPatel
        Super User

        Hi MojoGene,

         

        Please follow the below screenshots for the solution. It is tested and working fine.

         

        Create Calculated column for your hours column . if you already have one, you do not need to create one.Create another calculated column for yearfrac calculationYou can see the results in the screenshotCreate your desired measure for your final results.

         

        Thanks & Regards,

        Bhavesh