Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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?

 

 

I hope this makes sense 

 

I appreciate all help!

 

Kind regards Anna

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    I have taken a data sample for example:

     

    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])

     

    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.

7 Replies

  • 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.

    • Anonymous's avatar
      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!
      • jennratten's avatar
        jennratten
        Super User

        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.
  • 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.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi,

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

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    I have taken a data sample for example:

     

    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])

     

    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.