Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Comparing values to earlier values.

Hello,

I'm in a  bit of a pickle and can't figure out how to compare data values. Image for refference.


What I would like to do is to compare the names (left) with the values based upon dates. E.g.

Akrylux -124.90 - 11/10/2017 has increased by 26% on the date 2/28/2018. Just calculate a simple growth rate. 

growth= (present-past)/past

And then monthly - however some months dont have data - empty. Is there a way to treat those empty months as 0? And then show current month growth as 0? With the last growth figure by its side - with the last growth date?

The picture above is a Visualation (table) with the selected fields. name - sales - date.


Thank you for inputs.

Regards,
David.

  • Hi Anonymous,

     

    Please try to add calculated columns with below DAX:

    past =
    LOOKUPVALUE (
        Tb2[Values],
        Tb2[Names], Tb2[Names],
        Tb2[Dates], CALCULATE (
            MAX ( Tb2[Dates] ),
            FILTER ( ALLEXCEPT ( Tb2, Tb2[Names] ), Tb2[Dates] < EARLIER ( Tb2[Dates] ) )
        )
    )
    
    growth =
    IF ( Tb2[past] = BLANK (), 0, ( Tb2[Values] - Tb2[past] ) / Tb2[past] )

     





    And then monthly - however some months dont have data - empty. Is there a way to treat those empty months as 0? And then show current month growth as 0? With the last growth figure by its side - with the last growth date?

    I cannot understand above requirement well, please illustrate your desired result with more details.

     

    Best regards,

    Yuliana Gu

2 Replies

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi Anonymous,

     

    Please try to add calculated columns with below DAX:

    past =
    LOOKUPVALUE (
        Tb2[Values],
        Tb2[Names], Tb2[Names],
        Tb2[Dates], CALCULATE (
            MAX ( Tb2[Dates] ),
            FILTER ( ALLEXCEPT ( Tb2, Tb2[Names] ), Tb2[Dates] < EARLIER ( Tb2[Dates] ) )
        )
    )
    
    growth =
    IF ( Tb2[past] = BLANK (), 0, ( Tb2[Values] - Tb2[past] ) / Tb2[past] )

     





    And then monthly - however some months dont have data - empty. Is there a way to treat those empty months as 0? And then show current month growth as 0? With the last growth figure by its side - with the last growth date?

    I cannot understand above requirement well, please illustrate your desired result with more details.

     

    Best regards,

    Yuliana Gu

    • Anonymous's avatar
      Anonymous
      Not applicable

      When trying the dataset which is computed manually v-yulgu-msft it works like a charm! But the issue still persists with that error in a normal table.

      Thank you for your response v-yulgu-msft, however the callculated collumn shows me this error.
      "A table of multiple values was supplied when a single value was expected"

      Could the issue be that my NAMES (company) are related from another collumn and my vallues(margin real) are callculated collumn as well?

       



      Regarding the monthly growth what I would like to do is a moving average of monthly/ 3 months/ 6 months.
      I think I know how to do it (DAX below). But would like to do it by the Company (NAMES in your pbix). Not that advanced in DAX when it comes towards this.

      Moving 3 AVG =
      CALCULATE (
          AVERAGE ( Orders[Margin Real] );
          DATESINPERIOD (
              Orders[actual_delivery_date];
              LASTDATE ( Orders[actual_delivery_date] );
              -3;
              MONTH
          )
      )


      Thank you for your help and time v-yulgu-msft.