cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
forbi
Frequent Visitor

Value of the previous period according to the filter

ls.PNG

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?

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

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")

vxiaotang_0-1670222582252.png

vxiaotang_1-1670222613083.pngvxiaotang_2-1670222722726.png

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.

View solution in original post

1 REPLY 1
v-xiaotang
Community Support
Community Support

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")

vxiaotang_0-1670222582252.png

vxiaotang_1-1670222613083.pngvxiaotang_2-1670222722726.png

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.

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Dev Camp Session 30

Ted's Dev Camp - January 26, 2023

This session will provide guidance and teach campers the skills required to build Power BI reports that support multiple languages.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.