Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
for eg in nov 23 for product A having order of 50,
in dec 23 for product A having order of 45
output:
in jan 24 for product A order should be 50 + 40=90 (nov23 product A order + dec 23 product A order).
It has to go dynamically for feb 24, jan24+dec 23.
how to achieve this in power bi
Solved! Go to Solution.
Hi @sridharbabu
For your question, here is the method I provided:
Here's some dummy data
"Table"
Set the date type you need, for example: mmmm d.
Create a measure. Calculate the sum of orders in the last two months.
total order =
var max_date = CALCULATE(MAX('Table'[monthyear]), FILTER(ALL('Table'), 'Table'[Product] = MAX('Table'[Product])))
var start_date = EDATE(max_date, -2)
return
CALCULATE(
SUM('Table'[order]),
FILTER(
ALL('Table'),
'Table'[Product] = MAX('Table'[Product])
&&
'Table'[monthyear] >= start_date
&&
'Table'[monthyear] < max_date))
Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
It would help if you can provide a sample data and variations of date formats in your table.
Proud to be a Super User!
sample data
Product | location | monthyear | order | MonthSeq |
3245 | abc | Nov-23 | 34 | 23 |
3245 | abc | Oct-23 | 56 | 22 |
5255 | xyz | Nov-23 | 45 | 23 |
5255 | xyz | Oct-23 | 96 | 22 |
Hi @sridharbabu
For your question, here is the method I provided:
Here's some dummy data
"Table"
Set the date type you need, for example: mmmm d.
Create a measure. Calculate the sum of orders in the last two months.
total order =
var max_date = CALCULATE(MAX('Table'[monthyear]), FILTER(ALL('Table'), 'Table'[Product] = MAX('Table'[Product])))
var start_date = EDATE(max_date, -2)
return
CALCULATE(
SUM('Table'[order]),
FILTER(
ALL('Table'),
'Table'[Product] = MAX('Table'[Product])
&&
'Table'[monthyear] >= start_date
&&
'Table'[monthyear] < max_date))
Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
In continuation for above question, how can i display dynamically the previous two months data in table in power bi. loading data from sql to power bi. Every month add data to sql table. Dynamically has to show previous two months of data as table in power bi.
Date in table is of string format like Nov-23. How to use it.
Following DAX measure should correctly calculate the sum of orders for the two months preceding the month of the selected date.
Proud to be a Super User!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
72 | |
70 | |
57 | |
37 | |
36 |
User | Count |
---|---|
85 | |
65 | |
60 | |
46 | |
45 |