Forum Discussion

juanmobando's avatar
juanmobando
Frequent Visitor
8 years ago

variance between columns in a matrix

Good Morning All!

 

I have been able to create cool things on PowerBi. However, I am struggling trying to get a variance between values on columns.

 

I have two columns (see below) with the most critical information, one is Year and the other one is sales.

 

However, I am not able to create a variance between the values of one year of the other which are displayed in different columns.

 

I would be more than happy if anyone can give me some help with the topic!!!! 

 

My data in on the following format:

 

YearBrandLineSales
2016ABoxes 4931.4
2015ABoxes 14326.0
2014ABoxes 15179.6
2016BBoxes 7575.1
2015BBoxes 12087.0
2014BBoxes 1659.0

 

And I have been able to reproduce a matrix with values and weight over the total as follows:

 

 

Boxes2016% WeightVariance2015% WeightVariance2014% Weight
A4931.439.4%Needed Calculation14326.054.2%Needed Calculation15179.690.1%
7575.160.6%Needed Calculation12087.045.8%Needed Calculation1659.09.9%
Total12506.5100.0%Needed Calculation26413.0100.0%Needed Calculation16838.6100.0%

 

But I am obivously missing the fact that I could calculate A 2016 number against 2015 value, and so for the other item!

 

Thank you and merry Xmas everyone!!

 

 Do I need to create an additional table with the Years and create relationships? Any help would do great. :)

6 Replies

  • kcantor's avatar
    kcantor
    Icon for Community Champion rankCommunity Champion

    juanmobando

    You would be best served using a data dimension table and creating a second measure for Previous year. The you would use two measure to find the variance. For example in sales you might have:

    Total Sales = SUM(Sales[LineSales])

    Last year Sales = CALCULATE([Total Sales], DATEADD(DimDate[DateKey], -1, year)

    Variance = [Total Sales]-[Last year Sales]

    Of course going this route would requre you to drop the year from the columns and list your dates as rows using the measures as values. 

    • juanmobando's avatar
      juanmobando
      Frequent Visitor

      Hi kcantor Thank you very much for the guidance.

       

      So far I was not sure how to create a dimension table, but finally I managed to create them,

       

      I started by creating the table, and then assigning a dimension to the year as shown below:

       

       

      . I started by establishing a values  on the following format and also created a timestamp to define a year, as that is the only measure I need.

       

      Can you please confirm how to create the relationship between both tables?

       

      Now, when it comes to create the variance on the main table, I am not sure what sort of code should I follow, I tried yours but I am getting the following errorr on triying to display last year sales

       

       

      I am creating a Matrix table to show the information, not sure what I am missing here.

       

       

      Thank you very much!!!

       

       

       

       

      • parry2k's avatar
        parry2k
        Icon for Super User rankSuper User

        juanmobando you are setting relationship between year and date , both are different data type.

         

        Add a calculated column in your table to create a date and set relation on that column:

         

        - add column DummyDate (or name whatever you want) 

         

        DummyDate = Date(Table1[Year], 1,1)

        - go to modelling tab and set data type to Date

         

        - set relation on dummydate with your date dimention on date

         

         

  • v-jiascu-msft's avatar
    v-jiascu-msft
    Icon for Microsoft Employee rankMicrosoft Employee

    Hi juanmobando,

     

    Could you please mark the proper answer as solution or share the solution if it's convenient for you? That will be a big help to the others.

     

    Best Regards!
    Dale

    • juanmobando's avatar
      juanmobando
      Frequent Visitor

      Hi Dale,

       

      Thanks for the help.

       

      But I am afraid I cannot even create the first calculatio for the year 2014

       

       

      CALCULATE ( SUM ( Table1[Sales] ), Table1[Year] = 2014 )

      When I am creating the measure, I can only get to the first expression, but Bi does not allow me to enter the  Table1[Year] expression... 

       

      Therefore I cannot go any forward with the solution.

       

      Is there something I need to enable on the formulae or any options that I am not looking at that would be helpful? I am afraid that there is might be an issue of the syntax, because I tried but it does not allow me enter other field on the expression..

       

      Please let me know.

       

      Thank you!