Forum Discussion
Linear pacing calculation for the current Quarter
- Anonymous4 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 ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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.