Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
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?
| date | value | previous month value |
| 2024-01-01 | 10 | - |
| 2024-02-01 | 20 | 10 |
| 2024-03-01 | 30 | 20 |
| 2024-04-01 | 40 | 30 |
| 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 |
Solved! Go to Solution.
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:
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:
Hope this helps!!
If this solved your problem, please accept it as a solution!!
Best Regards,
Shahariar Hafiz
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.
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:
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:
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
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:
I have attached an example pbix file for your reference.
Best regards,
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.
| User | Count |
|---|---|
| 48 | |
| 40 | |
| 40 | |
| 20 | |
| 16 |
| User | Count |
|---|---|
| 70 | |
| 67 | |
| 32 | |
| 27 | |
| 26 |