Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Linear pacing calculation for the current Quarter

Hey guys,    I'd like to create a simple calculation that would spit out one number (%) based on the current Quarter we are in right now.  I call it Pacing%.   No. of Days in the current Quarter...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    Firstly, there should be a DimDate table in your data model.

    DimDate = 
    ADDCOLUMNS (
        CALENDAR ( DATE ( 2022, 01, 01 ), DATE ( 2022, 12, 31 ) ),
        "Year", YEAR ( [Date] ),
        "Qtr", QUARTER ( [Date] ),
        "Month", MONTH ( [Date] )
    )

    Then try this code to calcualte [Pacing%] by measure.

    Pacing % = 
    VAR _Today =
        DATE ( 2022, 03, 11 ) /* Today()*/
    VAR _Year =
        YEAR ( _Today )
    VAR _Qtr =
        QUARTER ( _Today )
    VAR _No_of_Days_in_the_current_Quarter =
        CALCULATE (
            COUNTROWS ( DimDate ),
            FILTER ( ALL ( DimDate ), DimDate[Year] = _Year && DimDate[Qtr] = _Qtr )
        )
    VAR _Qtr_Begin =
        CALCULATE (
            MIN ( DimDate[Date] ),
            FILTER ( ALL ( DimDate ), DimDate[Year] = _Year && DimDate[Qtr] = _Qtr )
        )
    VAR _Days_in_within_current_Quarter =
        DATEDIFF ( _Qtr_Begin, _Today, DAY )
    RETURN
        DIVIDE ( _Days_in_within_current_Quarter, _No_of_Days_in_the_current_Quarter )

    In my code I use 2022/03/11 directly, if you want to get today's date, you can try Today() function. 

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

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