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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
carlosroston
Regular Visitor

How to get the previous month's value

Hello, I would like to obtain a measurement that returns the value of the previous month even if the date filter is unchecked.

I would like it to return the value of the month before the current month if the date filter is not selected.

 

In this first image the filters are selected and the returned value is correct.

Screenshot_1.png

 

 

However, in this second image with the filters unchecked, it returns the wrong value. I would like it to return the previous month of the current month.

Screenshot_2.png

 

Below is the DAX function I am using:

 

Mês Ant =
    CALCULATE(
        [Valor Total],
        DATEADD(
            d_Calendario[Data],
            -1,
            MONTH
        )
    )
2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

Your approach will fail because neither slicer is set to single select.  You are allowing your users to select multiple months as well as multiple years, so "previous month"  loses its meaning.

View solution in original post

Anonymous
Not applicable

Hi @carlosroston ,

I create two tables as you mentioned.

vyilongmsft_0-1735787810217.png

vyilongmsft_1-1735787834027.png

vyilongmsft_2-1735787931207.png

Then I create two measures and here are their DAX codes.

Measure = 
IF(
    ISFILTERED('DateTable'[Month]),
    CALCULATE(
        SUM('SalesData'[SalesAmount]),
        FILTER(
            'DateTable',
            'DateTable'[Month] = SELECTEDVALUE('DateTable'[Month])
        )
    ),
    CALCULATE(
        SUM('SalesData'[SalesAmount]),
        FILTER(
            'DateTable',
            'DateTable'[Month] = MONTH(TODAY()) - 1
        )
    )
)
Measure 2 = 'SalesData'[Measure] - 100

But as lbendlin said, you have to keep an option in Slicer or you won't be able to accomplish what you want to accomplish.

vyilongmsft_4-1735788184471.png

vyilongmsft_5-1735788209562.png

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @carlosroston ,

I create two tables as you mentioned.

vyilongmsft_0-1735787810217.png

vyilongmsft_1-1735787834027.png

vyilongmsft_2-1735787931207.png

Then I create two measures and here are their DAX codes.

Measure = 
IF(
    ISFILTERED('DateTable'[Month]),
    CALCULATE(
        SUM('SalesData'[SalesAmount]),
        FILTER(
            'DateTable',
            'DateTable'[Month] = SELECTEDVALUE('DateTable'[Month])
        )
    ),
    CALCULATE(
        SUM('SalesData'[SalesAmount]),
        FILTER(
            'DateTable',
            'DateTable'[Month] = MONTH(TODAY()) - 1
        )
    )
)
Measure 2 = 'SalesData'[Measure] - 100

But as lbendlin said, you have to keep an option in Slicer or you won't be able to accomplish what you want to accomplish.

vyilongmsft_4-1735788184471.png

vyilongmsft_5-1735788209562.png

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Your approach will fail because neither slicer is set to single select.  You are allowing your users to select multiple months as well as multiple years, so "previous month"  loses its meaning.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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