I have 2 measures, where depending on the date filters selected, I show:
Last 12 months:
CALCULATE
(
[Xyz] , DATESINPERIOD ( 'Date'[Date] , MAX('Date'[Date]) , -12 , MONTH )
)
I need to do the same, but for months -12 to -24.
I have tried, but DATEADD doesn’t seem to work with MAX…
var dat = MAX('Date'[Date])
RETURN
CALCULATE
(
[Xyz] ,
DATESINPERIOD(
'Date'[Date],
DATEADD(dat,-12,MONTH) ,-24,MONTH)
)
How can I make the period from -12 to -24 ?
What if you try this ????? Even If I haven't tested it yet. I know you can nest Time Intelligence Functions.
_12_24 Period =
CALCULATE (
[Xyz],
SAMEPERIODLASTYEAR (
DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -12, MONTH )
)
)
Related
I have a Financial Year filter that does not select before 2021 . This is because there is PAGE level Filter that only allows the last 2 years , so only 2021 to 2023 .
Problem is that I have a 14 w Rolling Average, that when the 1st week in 2021 is selected, it does not work .
Code for measure
CALCULATE (
DISTINCTCOUNT ( Sales[activity_id] ),
FILTER (
Sales,
Sales[done] = "Yes"
&& Sales[activity_type]
IN { "In-Person Meeting", "Virtual Meeting", "Site Visit" }
) )
Code for Caluclation group
VAR __lastVisibleDate =
LASTDATE ( 'Calendar'[Date] )
VAR _fromDate =
CALCULATE ( DATEADD ( __lastVisibleDate, -91, DAY ), ALL ( 'Time') )
VAR __result =
CALCULATE (
SELECTEDMEASURE (),
REMOVEFILTERS ( 'Calendar' ),
'Calendar'[Date] > _fromDate
&& 'Calendar'[Date] <= __lastVisibleDate
)
VAR _result_divide =
DIVIDE ( __result, 13, 0 )
RETURN
IF ( _result_divide < 0.1, BLANK (), _result_divide )
I have tried every combination of ALL('Calendar' ) to get the rolling 14 week average to work for the 1st week of Jan 2021 . Debugging the _fromDate does give me the 20/10/2020 but the rolling average still does not work out correctly ! Argghhh !
Any ideas ? This is proving quite diffcicult
The PAGE level filter is needed to allow the user to select the financial year .
I am looking to get the sum of sales for the last 3 months. not including the unfinished month which is this month.
I have this Dax but its not accepting the DATEADD with the MAX. Is there any workaround?
Measure1 = CALCULATE (
SUM ( table1[Sales] ),
DATESINPERIOD (
table1[date],
DATEADD( MAX ( table1[date] ), -1,MONTH),
-3,
MONTH
)
)
DATEADD function requires a set of dates to computation. That is why it not works with MAX, which returns single value. Find more here.
You need to find the maximum date in the dataset, then filter out the current month from the date table. Try the measure as follows:
Measure1 =
VAR maxDate =
CALCULATE(
MAX( 'Calendar'[Date] ),
ALL('Calendar' )
)
VAR firstDay = DATE( YEAR( maxDate ), MONTH( maxDate ), 1 )
VAR maxK =
CALCULATE(
MAX('Calendar'[Date] ),
'Calendar'[Date] < firstDay
)
VAR result =
CALCULATE(
SUM( AmountPaid[PaymentAmt] ),
DATESINPERIOD('Calendar'[Date], maxK, -3, MONTH )
)
return result
The maxK part calculates maximum date excluding the latest month in my dataset. You have to adjust the measure a bit for your needs (e.g. use TODAY() instead maxDate).
Hope it helps.
I have the following fields:
Year
Category
Maker
Month
Month Number
Sales Volume
Sales
Date
So, I have in my dash a filter for "Month Number" and "Year":
My goal is to create two new measure; first with the Rolling Year that need to sum 12 months, ending in the moment that the user select in the mencioned filters. For example if y select Year 2021 and Month 01. The Rolling Year need to sum the sales of a selected category since 2020-02 to 2021-01 (thats mean always 12 months since a pivot month).
For thesecond is exactly the same, a measure called Rolling Last Year, it need to be a rolling sum too, but for the last period in order to compare. Taking the same example if I have the period 2020-02 to 2021-01. The Rolling Last Year for the last period should be 2019-02 to 2020-01.
I tried with this DAX code, that extracted from Microsoft page but without success:
Rolling Year =
CALCULATE (
SUMX ( Table, Table[Sales] ),
FILTER (
ALL (Table[Date] ),
AND (
Table[Date] <= MAX ( Table[Date] ),
DATEADD ( Table[Date], 12, MONTH ) > MAX ( Table[Date] ))))
I share you an extract of my base:
Thanks in advance !!!
Based on the table and code you have shared, it is unclear from where the date filters are being applied. In case you have not done it, I strongly suggest to delete the [Month] and [Month Number] field from your Sales table and keep them in a separate Calendar table, from where the filters should be selected. Then, a simple tweak on you current formula should do the trick:
Rolling Year =
CALCULATE (
SUMX ( Table, Table[Sales] ),
FILTER (
ALL ('Calendar'[Date] ),
AND (
Table[Date] <= MAX ( 'Calendar'[Date] ),
DATEADD ( 'Calendar'[Date], 12, MONTH ) > MAX ( 'Calendar'[Date] ))))
However you can try with this variation for the code, a little bit optimized so as not to scan your whole Sales table each time:
Rolling Year =
VAR EndSelectedDate = MAX ( 'Calendar'[Date] )
VAR StartSelectedDate =
CALCULATE (
MAX ( 'Calendar'[Date] ),
ALL ( 'Calendar'[Year] ),
'Calendar'[Year]
= MAX ( 'Calendar'[Year] ) - 1
)
RETURN
CALCULATE (
SUM ( Table[Sales] ),
ALL ( 'Calendar' ),
'Calendar'[Date] <= EndSelectedDate,
'Calendar'[Date] > StartSelectedDate
)
have a simple table like this
ID value date
A 100 2020-01-01
B 80 2019-01-01
A 90 2022-01-01
A 130 2021-01-01
B 100 2021-01-01
and want to know how many IDs had 10% increase within a selected time period, IDs might not necessarily have an entry on Min(Date) or Max(Date), I'd like to know the difference between first and last value within the selected time period
I came up with something like this but not sure if it's working :
Measure=
Var FirstValue=
SUMX (
VALUES( table [ID] ),
CALCULATE ( MIN ( table[value]), FIRSTDATE ( 'Date'[DATE] ) )
)
Var LastValue =
SUMX (
VALUES( table[ID] ),
CALCULATE ( MIN ( table[value] ), LASTDATE ( 'Date'[DATE]) )
)
Return sumx(table,if( (FirstValue -LastValue )/FirstValue> 0.1 , 1,0)
)
Can anyone help me with this formula?
Calculate formula not totaling
Rev SWLY2 =
CALCULATE (
SUM ( 'Fact Table'[[Revenue Net]]] ),
FILTER (
ALL ( DateTable ),
DateTable[WeekID] = SELECTEDVALUE ( DateTable[WeekID] ) - 52
)
)
For the total, SELECTEDVALUE ( DateTable[WeekID] ) returns a blank because there are multiple weeks within the filter context.
Try using MAX in the case instead of SELECTEDVALUE.
Edit: I think this should work as you'd expect:
Rev SWLY2 =
CALCULATE (
SUM ( 'Fact Table'[[Revenue Net]]] ),
FILTER (
ALL ( DateTable ),
DateTable[WeekID] + 52 IN VALUES ( DateTable[WeekID] )
)
)
Note that VALUES is a list when there are more than one values.