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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Add previous month data in same table

Hi,

 

I need to calculate the change in bruttoprice in this month compared to last month by each productnumber. The only way I can think of to do that is by adding a column in my table that shows previous month bruttoprice next to this months bruttoprice. 

My list shows all productnumbers per month, so that several month data are in the same table. 

I have tried to add a column with

Previous month bruttopris = CALCULATE(MIN(XAL_Intego34456[Bruttopris]),PREVIOUSMONTH('Date'[Date]))
But this results in blank entries.
 
How do I match the value of this month with the one from the previous month?

 

annalundsgaard_0-1638890014882.png

 

I hope this makes sense 

 

I appreciate all help!

 

Kind regards Anna

 

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

I have taken a data sample for example:

Eyelyn9_0-1639115931744.png

 

According to my understanding, since December has Product A,B, so you want to get the A+B = 6+7=13 of November, and do not Product C,right ? So, in summary the output should should be:

December -->  A+B 6+7=13
November -->  A+B+C=3+4+5=12

October    -->  A+B=1+2=3

 

If so,please try:

Measure = 
var _t=SUMMARIZE(FILTER(ALL(XAL_Intego34456),YEAR([Date])=YEAR(MAX('XAL_Intego34456'[Date])) && MONTH([Date])=MONTH(MAX('XAL_Intego34456'[Date]))),[Productnumber])
return SUMX(FILTER(ALL('XAL_Intego34456'),YEAR([Date])=YEAR(MAX('XAL_Intego34456'[Date])) && MONTH([Date])=MONTH(MAX('XAL_Intego34456'[Date]))-1  &&  [Productnumber] in _t),[Bruttopris])

Eyelyn9_1-1639116299552.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

I have taken a data sample for example:

Eyelyn9_0-1639115931744.png

 

According to my understanding, since December has Product A,B, so you want to get the A+B = 6+7=13 of November, and do not Product C,right ? So, in summary the output should should be:

December -->  A+B 6+7=13
November -->  A+B+C=3+4+5=12

October    -->  A+B=1+2=3

 

If so,please try:

Measure = 
var _t=SUMMARIZE(FILTER(ALL(XAL_Intego34456),YEAR([Date])=YEAR(MAX('XAL_Intego34456'[Date])) && MONTH([Date])=MONTH(MAX('XAL_Intego34456'[Date]))),[Productnumber])
return SUMX(FILTER(ALL('XAL_Intego34456'),YEAR([Date])=YEAR(MAX('XAL_Intego34456'[Date])) && MONTH([Date])=MONTH(MAX('XAL_Intego34456'[Date]))-1  &&  [Productnumber] in _t),[Bruttopris])

Eyelyn9_1-1639116299552.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

parry2k
Super User
Super User

@Anonymous try this

 

Prev month bruttopris = CALCULATE(sum(XAL_Intego34456[Bruttopris]),PREVIOUSMONTH('Date'[Date]))
* DIVIDE ( um(XAL_Intego34456[Bruttopris]), um(XAL_Intego34456[Bruttopris]) )

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi,

I'm sorry but the "um" part doesn't work - what is this supposed to do?

jennratten
Super User
Super User

Hello - here is a great resources with examples for standard time intelligence measures, including current and previous month.

https://www.daxpatterns.com/month-related-calculations/ 

parry2k
Super User
Super User

@Anonymous you should add this as a measure, not column.

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi,

 

The issue is that when I add it as a measure, I write 

Prev month bruttopris = CALCULATE(sum(XAL_Intego34456[Bruttopris]),PREVIOUSMONTH('Date'[Date]))
 
And then I get the sum of the bruttoprice for all products that were bought last month. However, some products are not re-bought in the current month, hence those should be excluded from the sum. Do you have any suggestions as to how I get the bruttoprice from last month for only the products that were bought this month?
 
I need it to calculate the total purchase in this month based on previous month's prices.
 
Thank you!

You will need to use separate measures - also made sure you have the proper tables and relationships in your model:

  • Measures
    • Product price per unit (sumx).
    • Quantities per product (sumx).
    • Sales $ (Product price per unit x Quantities per product)
    • Create variations of Sales $ for different date ranges using time intelligence patterns.
  • Matrix visual
    • Drop your measures in the values and dimensions in rows/columns based on your preference.  Month would usually be in the columns so you can show Sales with this month's sales vs last month, etc.
  •  Tables
    • Dim table with a list of products, prices per unit, price date.
    • Dim products.
    • Dim date table.
    • Fact Sales table with product, transaction date, quantities sold.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.