Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi
Pls help to correct my DAX, Im trying to get the total Sales Amount till previous week (01 Jan to the MAX iso week -1)
Sales Amount YTD till Prev Week =
CALCULATE(
SUM('Sales'[Amount]),
FILTER(
ALL('Date'[Date]),
'Date'[Date] = MAX('Date'[ISO Week Number]) -1
)
)
Sales Amount YTD till Prev Week =
VAR _lastWeekNumber = MAXX(ALL('Date'),[ISO Week Number])
VAR _lastDate = CALCULATE(MAX('Date'[Date]),'Date'[ISO Week Number]=_lastWeekNumber-1)
VAR _CurrentYear = YEAR(_lastDate)
VAR _RESULTS=
CALCULATE(SUM('Sales'[Amount]), 'Date'[year]=_CurrentYear&&'Date'[Date]<=_lastDate)
OR
Sales Amount YTD till Prev Week =
VAR _lastWeekNumber = LASTNONBLANK('Date'[ISO Week Number],[Amount])
VAR _lastDate = CALCULATE(MAX('Date'[Date]),'Date'[ISO Week Number]=_lastWeekNumber-1)
VAR _CurrentYear = YEAR(_lastDate)
VAR _RESULTS=
CALCULATE(SUM('Sales'[Amount]), 'Date'[year]=_CurrentYear&&'Date'[Date]<=_lastDate)
Sales Amount YTD till Prev Week =
VAR _lastDate = CALCULATE(MAX('Date'[Date]),'Date'[Date] = MAX('Date'[ISO Week Number]) -1)
VAR _CurrentYear = YEAR(_lastDate)
VAR _RESULTS=
CALCULATE(SUM('Sales'[Amount]), 'Date'[year]=_CurrentYear&&'Date'[Date]<=_lastDate)
incorrect syntax
no need to copy but need to write by hand
and you need to have year column in calendar table
there is Year column still got the same syntax error
do you have this column in your calendar table?
Yes i have or is it possible to modify from this code?
Volume =
VAR _lastDate =
CALCULATE ( MAX ( 'DP_volume'[in_date] ), REMOVEFILTERS ( 'Date' ) )
VAR _lastWeekNumber =
CALCULATE (
MAX ( 'Date'[ISO Week Sequential] ) -1,
'Date'[Date] = _lastDate,
REMOVEFILTERS ( 'Date' )
)
VAR _result =
CALCULATE (SUM('DP_volume'[TEUs]),
'Date'[Year] && 'Date'[Date] <= _lastDate,
REMOVEFILTERS ( 'Date' )
)
RETURN (
_result
)
Volume =
VAR _lastDate =
CALCULATE ( MAX ( 'DP_volume'[in_date] ), REMOVEFILTERS ( 'Date' ) )
VAR _lastWeekNumber =
CALCULATE (
MAX ( 'Date'[ISO Week Sequential] ) -1,
'Date'[Date] = _lastDate,
REMOVEFILTERS ( 'Date' )
)
VAR _CurrentYear = YEAR(_lastDate)
VAR _result =
CALCULATE (SUM('DP_volume'[TEUs]),
'Date'[Year] =_CurrentYear&& 'Date'[Date] <= _lastDate,
REMOVEFILTERS ( 'Date' ))
RETURN
_result
I think you just change from "=" to "<=" for YTD accumulated sales , please see below
'Date'[Date] <= MAX('Date'[ISO Week Number]) -1
Sales Amount YTD till Prev Week =
CALCULATE(
SUM('Sales'[Amount]),
FILTER(
ALL('Date'[Date]),
'Date'[Date] <= MAX('Date'[ISO Week Number]) -1
)
)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
100 | |
81 | |
70 | |
62 |
User | Count |
---|---|
148 | |
116 | |
104 | |
90 | |
65 |