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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors