Forum Discussion
DAX : Sum previous month automatically
Hello,
I would like to translate this into DAX language:
I have a column calculated with the value of each item sold and a column with the date of sale of each item.
I would like to create a measure that gives me the total value sold for the month before last. So the current month minus -1.
For example, we are in June, I would like to know the total value sold in May. When we are in July, I would like my measure to automatically calculate the total value sold in June.
Thanks in advance
- Anonymous4 years ago
Hi PBIBeginner2022 ,
This formula should work.
Pre_sales = CALCULATE ( SUM ( 'Table'[Price] ), FILTER ( ALLSELECTED ( 'Table' ), FORMAT ( 'Table'[Date], "YYYYMM" ) = FORMAT ( EDATE ( TODAY (), -1 ), "YYYYMM" ) ) )Best Regards,
Jay
13 Replies
- Hariharan_R
Solution Sage
Hi,
Try below measure.
Previous Month Sales = CALCULATE(SUM(Sales[Sales]),PREVIOUSMONTH('Date'[Date]))- PBIBeginner2022
Helper III
Hi Hariharan_R
When I try this, it's wrote "vide" in French (void I Think).
CALCULATE(SUM(......) is good but after to select only the month minus 1 it's complicate because I have date with this format "01/04/2022" for exemple between year 1988 and 2024 ....
- bettyfishNew Member
when i try this the very first month, instead of being blank, includes the total of all rows
beg bal BS = var result = calculate([FTP-TTD],PREVIOUSMONTH('tbl_Calendar'[Date]))would you have any idea what i can be doing wrong??thanks!
betty
- Ashish_Mathur
Super User
Hi,
Share the download link of the PBI file and show the problem there very clearly.
- AnonymousNot applicable
Hi PBIBeginner2022 ,
Please try these formulas.
Column:
Pre_sales = SUMX ( FILTER ( ALLSELECTED ( 'Table' ), 'Table'[date] = EDATE ( EARLIER ( 'Table'[date] ), -1 ) ), 'Table'[value] )Measure:
Pre_sales = SUMX ( FILTER ( ALLSELECTED ( 'Table' ), 'Table'[date] = EDATE ( SELECTEDVALUE ( 'Table'[date] ), -1 ) ), 'Table'[value] )If it doesn't work, please share some sample data and expected result so that we could test the formula.
Best Regards,
Jay
- PBIBeginner2022
Helper III
Hi,
I tried your measurement, but I still have the same problem, no value is displayed. Here is a data set:
I want the sum of the actual month -1. So we are in June, I want the sum of price in May.
Article Price Date ART0001 43 11/06/2022 ART0002 235 19/05/2022 ART0003 43 12/06/2022 ART0004 987 23/05/2022 ART0005 4 13/06/2022 ART0006 54 02/06/2022 ART0007 7 11/08/2022 ART0008 65342 08/06/2022 ART0009 87 13/05/2022 ART0010 342 09/05/2022 ART0011 0 07/06/2022 ART0012 7 28/05/2022 ART0013 34 30/04/2022 ART0014 65 18/05/2022 ART0015 32 13/07/2022 ART0016 9 14/05/2022 ART0017 2 10/08/2022 ART0018 43 05/06/2022 ART0019 235 19/04/2022 ART0020 43 25/08/2022 ART0021 987 11/05/2022 ART0022 4 12/07/2022 ART0023 54 10/05/2022 ART0024 7 24/08/2022 ART0025 65342 30/06/2022 ART0026 87 06/05/2022 ART0027 342 24/04/2022 ART0028 0 21/06/2022 ART0029 7 04/05/2022 ART0030 34 05/05/2022 ART0031 65 17/05/2022 ART0032 96 05/07/2022 ART0033 127 26/05/2022 ART0034 158 25/08/2022 ART0035 189 31/07/2022 ART0036 220 26/08/2022 ART0037 251 03/07/2022 ART0038 282 19/07/2022 ART0039 313 18/05/2022 ART0040 344 14/06/2022 - AnonymousNot applicable
Hi PBIBeginner2022 ,
Thank you for the data.
Please try this formula:Pre_sales = CALCULATE ( SUM ( 'Table'[Price] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Date].[MonthNo] = SELECTEDVALUE ( 'Table'[Date].[MonthNo] ) - 1 ) )Best Regards,
Jay