Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hi all,
I am a beginner with Power BI and I need help on this.
I need to calcule sales for last month and sales for the year of last month.
For example:
1. If today is 29/01/2019 => I should calculate:
-the sales for 12/2018 (all sales month)
AND
- the sales for all the year 2018 (from Januar to December)
2. If today is 15/03/2019 => I should calculate:
-the sales for 02/2019 (all sales month)
AND
- the sales for the year 2019 (from Januar to December)
Your help is much appreciated.
Thanks
Solved! Go to Solution.
Hi @VEOMBOTEST,
For your requiement, I have made a simple test pbix to reproduce your scenario.
You could refer to the measures below.
last month_ = VAR currentmonth = MONTH ( MAX ( 'Data'[Date] ) ) VAR lastmonth = IF ( currentmonth = 1, 12, currentmonth - 1 ) VAR currentyear = YEAR ( MAX ( 'Data'[Date] ) ) VAR the_year_of_lastmonth = IF ( currentmonth = 1, currentyear - 1, currentyear ) RETURN CALCULATE ( SUM ( Data[Amount] ), FILTER ( 'Data', MONTH ( 'Data'[Date] ) = lastmonth && YEAR ( 'Data'[Date] ) = the_year_of_lastmonth ) ) the year of last month = VAR currentmont = MONTH ( MAX ( 'Data'[Date] ) ) VAR lastmonth = IF ( currentmont = 1, 12, currentmont - 1 ) VAR currentyear = YEAR ( MAX ( 'Data'[Date] ) ) VAR the_year_of_lastmonth = IF ( currentmont = 1, currentyear - 1, currentyear ) RETURN CALCULATE ( SUM ( Data[Amount] ), FILTER ( 'Data', YEAR ( 'Data'[Date] ) = the_year_of_lastmonth ) )
If you want to calculated the sales of last month for each month, you may need to create another date table and then create the relationship between the tables, then create the measure like to calculate the last month value.
last month = CALCULATE(SUM(Data[Amount]),DATEADD('Data'[Date],-1,MONTH))
More details, you could refer to my attachment.
Best Regards,
Cherry
Hi @VEOMBOTEST,
For your requiement, I have made a simple test pbix to reproduce your scenario.
You could refer to the measures below.
last month_ = VAR currentmonth = MONTH ( MAX ( 'Data'[Date] ) ) VAR lastmonth = IF ( currentmonth = 1, 12, currentmonth - 1 ) VAR currentyear = YEAR ( MAX ( 'Data'[Date] ) ) VAR the_year_of_lastmonth = IF ( currentmonth = 1, currentyear - 1, currentyear ) RETURN CALCULATE ( SUM ( Data[Amount] ), FILTER ( 'Data', MONTH ( 'Data'[Date] ) = lastmonth && YEAR ( 'Data'[Date] ) = the_year_of_lastmonth ) ) the year of last month = VAR currentmont = MONTH ( MAX ( 'Data'[Date] ) ) VAR lastmonth = IF ( currentmont = 1, 12, currentmont - 1 ) VAR currentyear = YEAR ( MAX ( 'Data'[Date] ) ) VAR the_year_of_lastmonth = IF ( currentmont = 1, currentyear - 1, currentyear ) RETURN CALCULATE ( SUM ( Data[Amount] ), FILTER ( 'Data', YEAR ( 'Data'[Date] ) = the_year_of_lastmonth ) )
If you want to calculated the sales of last month for each month, you may need to create another date table and then create the relationship between the tables, then create the measure like to calculate the last month value.
last month = CALCULATE(SUM(Data[Amount]),DATEADD('Data'[Date],-1,MONTH))
More details, you could refer to my attachment.
Best Regards,
Cherry
See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
87 | |
81 | |
53 | |
37 | |
35 |