Forum Discussion

Robbinsbk's avatar
Robbinsbk
Regular Visitor
6 years ago
Solved

Add a calculated column to a Matrix visualization

I am using a Power Bi matrix visualization to display a series of data. I have two datasources.  The first is my data I want to display and the second is my target values.  There is a Mant to One relationship between my source data and my target data.  Power BI piked up the relationship when I imported the data. 

 

I add to my source data a new column that is simply two of the colmns add together.  I add a second column which is the target from second table.  There are no slicers for filtering.  The data in the first two columns displays correctly.

 

I want to add a 3rd column that is my new column(named Target) - my new column(named SuperMarket WIP)  

This is my issue is doesn't display the correct amount.  It only gives me the options to choose the agregate functions.  As you can see from my snapshot, the calculation isn't what I am looking for.  My expectation are on the first row for example the new column (named Count of Gap) is 27 I expected - 3

 

SuperMarket WIP = (SuperMarketData[Before SuperMarket] + SuperMarketData[In SuperMarket])
Target = RELATED(TargetData[TARGET])
 
I believe it is related to filtering but can't figure the correct format.
 
I have tried a couple different scenarios
 
Gap = SuperMarketData[Target] - SuperMarketData[SuperMarket WIP]
 
Gap = RELATED(TargetData[TARGET] - (SuperMarketData[Before SuperMarket] + SuperMarketData[In SuperMarket])
 
Gap = RELATED(TargetData[TARGET]) - CALCULATE(SUMX(SuperMarketData, SuperMarketData[Before SuperMarket] + SuperMarketData[In SuperMarket]),FILTER(SuperMarketData, SuperMarketData[Die Type] = RELATED(TargetData[DIE_TYPE])))
 
Any help or suggestions would be greatly appreciated.
 
Thank you.
  • Got it to work.  (Used a new name) What I did was use a measure.  I only wanted one value for the target. The relationship is Many to One.  Since there is only one value in the target type for each category I used MIN (again because there is only one value I could have just as easily used MAX) instead of sum for the target.

     

    To Be Released = CALCULATE( MIN(SuperMarketData[Target]),ALLSELECTED(TargetData)) - CALCULATE( SUM(SuperMarketData[Before SuperMarket]) + SUM(SuperMarketData[In SuperMarket]),ALLSELECTED(TargetData))
     

     

     

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Is your "GAP" column in the matrix a calculated column or a measure? Make sure it is a calculated column and then select SUM as the aggregation.

     

    If this helps please kudo.

    If this solves your problem please accept it as a solution.

    • Robbinsbk's avatar
      Robbinsbk
      Regular Visitor

      Yes, it is a calculated column.  I tried a couple different calculations but none is working.

       

      Gap = SUM(SuperMarketData[Target]) - SUM(SuperMarketData[SuperMarket WIP])
      Gap = CALCULATE(SUM(SuperMarketData[SuperMarket WIP]) - SUM(SuperMarketData[Target]))

      Gap = CALCULATE(SUM(SuperMarketData[Target]) - SUM(SuperMarketData[SuperMarket WIP]),FILTER(SUMMARIZE(SuperMarketData,SuperMarketData[Die Type]),SuperMarketData[Die Type]=RELATED(TargetData[DIE_TYPE])))
       
      • Robbinsbk's avatar
        Robbinsbk
        Regular Visitor

        Got it to work.  (Used a new name) What I did was use a measure.  I only wanted one value for the target. The relationship is Many to One.  Since there is only one value in the target type for each category I used MIN (again because there is only one value I could have just as easily used MAX) instead of sum for the target.

         

        To Be Released = CALCULATE( MIN(SuperMarketData[Target]),ALLSELECTED(TargetData)) - CALCULATE( SUM(SuperMarketData[Before SuperMarket]) + SUM(SuperMarketData[In SuperMarket]),ALLSELECTED(TargetData))