I want to create a measure that calculates the value of the "Objectif" measure of the previous period according to the date filter:
For example :
if filter on Year 2021 take the value of 2020
if filter on Qt4 2021 take the value of Qt 3 2021
if filter october 2021 take the value of september 2021
Automatically in dax?
Solved! Go to Solution.
Hi @forbi
yeah, here's an example,
Measure =
var _year= ISFILTERED('calendar'[Year])
var _quarter= ISFILTERED('calendar'[Quarter])
var _month = ISFILTERED('calendar'[Month])
return
SWITCH(TRUE(),
_year=TRUE() && _quarter= FALSE(), SELECTEDVALUE('calendar'[Year])-1&"",
_quarter=TRUE() && _month= FALSE(), SELECTEDVALUE('calendar'[Year]) &"-"& SELECTEDVALUE('calendar'[Quarter])-1,
_month=TRUE(),SELECTEDVALUE('calendar'[Year]) &"-"& SELECTEDVALUE('calendar'[Quarter])&"-"& SELECTEDVALUE('calendar'[Month])-1,
"please select")
sum of period =
VAR _year =
ISFILTERED ( 'calendar'[Year] )
VAR _quarter =
ISFILTERED ( 'calendar'[Quarter] )
VAR _month =
ISFILTERED ( 'calendar'[Month] )
RETURN
SWITCH (
TRUE (),
_year = TRUE ()
&& _quarter = FALSE (),
SUMX (
FILTER (
'Table',
YEAR ( 'Table'[Date] )
= SELECTEDVALUE ( 'calendar'[Year] ) - 1
),
[value]
),
_quarter = TRUE ()
&& _month = FALSE (),
SUMX (
FILTER (
'Table',
YEAR ( 'Table'[Date] ) = SELECTEDVALUE ( 'calendar'[Year] )
&& QUARTER ( 'Table'[Date] )
= SELECTEDVALUE ( 'calendar'[Quarter] ) - 1
),
[value]
),
_month = TRUE (),
SUMX (
FILTER (
'Table',
YEAR ( 'Table'[Date] ) = SELECTEDVALUE ( 'calendar'[Year] )
&& MONTH ( 'Table'[Date] )
= SELECTEDVALUE ( 'calendar'[Month] ) - 1
),
[value]
),
"please select"
)
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
Hi @forbi
yeah, here's an example,
Measure =
var _year= ISFILTERED('calendar'[Year])
var _quarter= ISFILTERED('calendar'[Quarter])
var _month = ISFILTERED('calendar'[Month])
return
SWITCH(TRUE(),
_year=TRUE() && _quarter= FALSE(), SELECTEDVALUE('calendar'[Year])-1&"",
_quarter=TRUE() && _month= FALSE(), SELECTEDVALUE('calendar'[Year]) &"-"& SELECTEDVALUE('calendar'[Quarter])-1,
_month=TRUE(),SELECTEDVALUE('calendar'[Year]) &"-"& SELECTEDVALUE('calendar'[Quarter])&"-"& SELECTEDVALUE('calendar'[Month])-1,
"please select")
sum of period =
VAR _year =
ISFILTERED ( 'calendar'[Year] )
VAR _quarter =
ISFILTERED ( 'calendar'[Quarter] )
VAR _month =
ISFILTERED ( 'calendar'[Month] )
RETURN
SWITCH (
TRUE (),
_year = TRUE ()
&& _quarter = FALSE (),
SUMX (
FILTER (
'Table',
YEAR ( 'Table'[Date] )
= SELECTEDVALUE ( 'calendar'[Year] ) - 1
),
[value]
),
_quarter = TRUE ()
&& _month = FALSE (),
SUMX (
FILTER (
'Table',
YEAR ( 'Table'[Date] ) = SELECTEDVALUE ( 'calendar'[Year] )
&& QUARTER ( 'Table'[Date] )
= SELECTEDVALUE ( 'calendar'[Quarter] ) - 1
),
[value]
),
_month = TRUE (),
SUMX (
FILTER (
'Table',
YEAR ( 'Table'[Date] ) = SELECTEDVALUE ( 'calendar'[Year] )
&& MONTH ( 'Table'[Date] )
= SELECTEDVALUE ( 'calendar'[Month] ) - 1
),
[value]
),
"please select"
)
Best Regards,
Community Support Team _Tang
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.
This session will provide guidance and teach campers the skills required to build Power BI reports that support multiple languages.
Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!
User | Count |
---|---|
209 | |
53 | |
45 | |
43 | |
41 |
User | Count |
---|---|
297 | |
207 | |
75 | |
74 | |
68 |