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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Fighting21
Frequent Visitor

if i have one day in each month how can i get previous month value ?

if i haver data bellow

 

date          value
2024-01-01                      10
2024-02-01                      20
2024-03-01                      30
2024-04-01                      40

 

i want make bellow how can i?

 

datevalue                                                  previous                     month                        value
2024-01-01    10                             -
2024-02-01    20                            10
2024-03-01    30                            20
2024-04-01    40                           30

 

i tried bellow but it's not worked
previous month value = CALCULATE('table'[value],DATEADD('date table'[Date],-1,MONTH))
bellow data is not what i expect
date           value                  previous month value
2024-01-01              10                        10
2024-02-01              20                        20
2024-03-01              30                        30
2024-04-01              40                        40
1 ACCEPTED SOLUTION
shafiz_p
Resident Rockstar
Resident Rockstar

Thanks @DataNinja777  for the solution you provide. Want to provide another solution, incase don't need a date table.

 

Hello @Fighting21 ,

If you don't want to create seperate date table but want value of previous month (Since you have monthly data), you can try the below code:

 

PreviousMonthValue = 
VAR CurrentDate = 'Table'[Date]

VAR PreviousDate = 
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALL('Table'),
            'Table'[Date] < CurrentDate
        )
    )

VAR _result =
CALCULATE(
    SUM('Table'[value]),
    'Table'[Date] = PreviousDate
)

RETURN
_result

 

  Desired output:

shafiz_p_0-1728795705198.png

 

You can also create a measure instead of calculated column. Just a small change in CurrentDate variable. Wrap it with Max Function.

Previous Month Value = 
VAR CurrentDate = MAX('Table'[Date])

VAR PreviousDate = 
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALL('Table'),
            'Table'[Date] < CurrentDate
        )
    )

VAR _result =
CALCULATE(
    SUM('Table'[value]),
    'Table'[Date] = PreviousDate
)

RETURN
_result

 

Desired Output:

shafiz_p_1-1728796258082.png

Hope this helps!!

If this solved your problem, please accept it as a solution!!

 

Best Regards,
Shahariar Hafiz

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

To your visual, ensure that date are dragged from the Calendar Table.  Write this measure

PMV = calculate(sum('table'[value]),previousmonth('date table'[Date]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
shafiz_p
Resident Rockstar
Resident Rockstar

Thanks @DataNinja777  for the solution you provide. Want to provide another solution, incase don't need a date table.

 

Hello @Fighting21 ,

If you don't want to create seperate date table but want value of previous month (Since you have monthly data), you can try the below code:

 

PreviousMonthValue = 
VAR CurrentDate = 'Table'[Date]

VAR PreviousDate = 
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALL('Table'),
            'Table'[Date] < CurrentDate
        )
    )

VAR _result =
CALCULATE(
    SUM('Table'[value]),
    'Table'[Date] = PreviousDate
)

RETURN
_result

 

  Desired output:

shafiz_p_0-1728795705198.png

 

You can also create a measure instead of calculated column. Just a small change in CurrentDate variable. Wrap it with Max Function.

Previous Month Value = 
VAR CurrentDate = MAX('Table'[Date])

VAR PreviousDate = 
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALL('Table'),
            'Table'[Date] < CurrentDate
        )
    )

VAR _result =
CALCULATE(
    SUM('Table'[value]),
    'Table'[Date] = PreviousDate
)

RETURN
_result

 

Desired Output:

shafiz_p_1-1728796258082.png

Hope this helps!!

If this solved your problem, please accept it as a solution!!

 

Best Regards,
Shahariar Hafiz

Wow it's work ! Thank you very much

DataNinja777
Super User
Super User

Hi @Fighting21 ,

 

You can generate the desired output by writing a calculated column using the following formula:

previous month value = 
CALCULATE(
    SUM('Table'[value]), 
    PREVIOUSMONTH('Date table'[Date])
)

This will generate the output as shown below:

DataNinja777_0-1728794856152.png

I have attached an example pbix file for your reference.

 

Best regards,

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.