The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Dear Community,
Could you help me to adjust the DAX formula oF Rolling Avg 2Q yellow line to exclude the start point which is not enough data (2 quarter ) to calculate properly and the end point (2023Q2) as below ?
Rolling Avg 2Q =
VAR NumOfQuarters = 2
VAR LastCurrentDate =
MAX(DimDates[Date])
VAR Period =
DATESINPERIOD (DimDates[Date], LastCurrentDate, - NumOfQuarters, QUARTER )
VAR Result =
CALCULATE (
'Value/Qty Selection'[Value/Quantity]
/2,
Period
)
RETURN
Result
Hi,
I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
I hope the below can provide some ideas on how to create a solution for your datamodel.
Qty total: =
SUM( Sales[Quantity] )
Qty 2months rolling avg: =
VAR _currentrowquarterend =
MAX ( 'Calendar'[End of Quarter] )
VAR _conditiontable =
FILTER (
ADDCOLUMNS (
FILTER (
ALL ( 'Calendar'[End of Quarter], 'Calendar'[Year-Quarter] ),
'Calendar'[End of Quarter] <= _currentrowquarterend
),
"qty", [Qty total:]
),
[qty] <> BLANK ()
)
VAR _condition =
COUNTROWS ( _conditiontable ) >= 2
&& [Qty total:] <> BLANK ()
&& HASONEVALUE ( 'Calendar'[Year-Quarter] )
RETURN
DIVIDE ( _condition, _condition )
* CALCULATE (
[Qty total:],
WINDOW (
-1,
REL,
0,
REL,
ALL ( 'Calendar'[End of Quarter], 'Calendar'[Year-Quarter] ),
ORDERBY ( 'Calendar'[End of Quarter], ASC )
)
) / 2