Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.