Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Dynamic calculation for difference between two non-date matrix columns

I have a matrix with region related fields as the column headers.  A slicer for this matrix contains about 40 regional related fields available to populate the matrix columns.  I have instructions on the slicer telling end users to select only two regions from within the slicer.  This means any 2 of the 40 available region related fields can serve as coulmn headers.  My rows are populated with item numbers.  Currently my matrix shows the List Price for each item number in both of the chosen regions, see example.  I need a fourth column that calculates the difference between column 2 and column 3 no matter what two regions are selected from the region slicer.  I have tried a formula that relies on the Allselected function and an [Index] but the [Index] value goes unrecognized by Power BI.  

 

Part number/List Price    Region X    Region Y    Difference (this is the column I need help programming)    
ABC123100.00100.000
ABC456 50.0050.00
ABC78925.0030.005.00
DEF123600.00500.00-100.00
DEF45660.00 -60.00

 

 

Here is the calculation that is not working, note the error bar under the [Index] instances.  Should I have a separate column for [Index] or can I define [Index] within my calculation?  Is there a way to define column 2 and column 3 and then just take the difference no matter what the header says for these columns? 

 

Its frustrating when I can do something in Excel but not PowerBI.

 

 

 

EDIT:  I would ike to add that I am open minded to a solution where a user picks a region from one slicer, a second region from a second slicer and the matrix shows the list prices and any difference.

21 Replies

  • When you say "difference"  do you mean "difference based on the alphabetical order of the two regions picked by the user regardles which region they picked first" ?

     

    DAX can tell you which filters are applied but it has no idea in which sequence they were applied.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello lbendlin and thanks for your reply.  I need any difference between the two columns, the alphabetical order and the choice sequence order are irrelevant.  I will only need the difference between two columns, there will never be 3 or more coulmns.

      Thanks!

      • lbendlin's avatar
        lbendlin
        Super User

        In that case the difference between MIN(ALLSELECTED) and MAX(ALLSELECTED) should suffice.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello Ashish_Mathur , that worked!  It took me some time to figure out that the column subtotals needed to be turned on and relabeled from "Total" to "Difference" but as soon as that was solved it worked great.  Thanks again! 

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        You are welcome.  If my reply helped, please mark it as Answer.

    • SVM75's avatar
      SVM75
      Regular Visitor

      Hi Ashish, i'm facing the same problem but the file does not seem to be there anymore, any chance that you can send me the file or hint the solution? Thanks, SVM

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Hi,

        It is an old post.  I do not have that file.  Share som data to work with, explain the question and show the expected result.  Share data in a format that can be pasted in an MS Excel file.

  • Hi. Any ideas how to download the file as I cannot do that when clicking on the hyperlink? Thanks

    • Ashish_Mathur's avatar
      Ashish_Mathur
      Super User

      It is an old post.  I do not have that file now.  Please share some data, explain the question and show the expected result.  Either share the download link of the PBI file or share data in a format that can be pasted in an MS Excel file.

      • kien79's avatar
        kien79
        New Member

        I have similar situation. That's why I just wanted to deep dive into your file to see the details. The problem I got when clicking on the hyperlink is that it requests for One Drive sign-in and though I can sign in but it then say

        Something went wrong

        We're sorry, sign-in isn't working right now. But we're on it! Please try again later.
        If this problem persists, contact your support team and include these technical details:
        Correlation ID: 47483da1-e0ac-5000-ddec-306238a881db
        Date and Time: 7/17/2024 1:17:21 PM