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.
Hello,
In Dax, I have this measure:
_AVG 1Y Revenue v2 =
AVERAGEX (
DATESINPERIOD ( Date[Date], LASTDATE ( Date[Date] ), -1, YEAR ),
[Revenue]
)
How can I filter Date[Date] so that the average is calculated based on the working days column Date[isWorkingDay] (0 for weekends, 1 for working days)? putting in mind that DATESINPERIOD doesn't accept virtual tables as its first parameter?
Best regards,
Simon
Solved! Go to Solution.
Try
_AVG 1Y Revenue v2 =
VAR MaxDate =
MAX ( 'Date'[Date] )
VAR LastYear =
DATE ( YEAR ( MaxDate ) - 1, MONTH ( MaxDate ), DAY ( MaxDate ) )
VAR DatesToUse =
CALCULATETABLE (
VALUES ( 'Date'[Date] ),
'Date'[Date] >= LastYear
&& 'Date'[Date] < MaxDate
&& 'Date'[Is Working Day] = 1
)
RETURN
AVERAGEX ( DatesToUse, [Revenue] )
Try
_AVG 1Y Revenue v2 =
VAR MaxDate =
MAX ( 'Date'[Date] )
VAR LastYear =
DATE ( YEAR ( MaxDate ) - 1, MONTH ( MaxDate ), DAY ( MaxDate ) )
VAR DatesToUse =
CALCULATETABLE (
VALUES ( 'Date'[Date] ),
'Date'[Date] >= LastYear
&& 'Date'[Date] < MaxDate
&& 'Date'[Is Working Day] = 1
)
RETURN
AVERAGEX ( DatesToUse, [Revenue] )
User | Count |
---|---|
26 | |
10 | |
8 | |
6 | |
6 |
User | Count |
---|---|
31 | |
11 | |
10 | |
10 | |
9 |