Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dancarr22
Helper V
Helper V

Calculate the difference between two columns (without hard coding in formula) in matrix

Hello,

 

We have tickers for which we receive prices from multiple vendors on a daily basis.

i.e. We receive prices from 4 vendors for ticker ABC.  

PricingSource_Excel.PNG

 

 

 

 

 

 

 

We would like to show the difference (actual and as a %) between the different data sources in a matrix.

Should display the difference between current record and record to the left.  So, for Ticker ABC - would show difference between Bloomberg and IDC in column IDC.  

Bascially want to make this dynamic so if user chooses only 2 pricing sources it will calculate the difference between those two.  But, if three are chosen then if will show the difference between  1 and 2 -- then 2 and 3.

 

PricingSource_PBI.PNG

Basically want this to work like Tableau (not trying to promote Tableau -- just wanted to show example of how it should work)

 

PricingSource_Tableau.PNG

 

Assuming some way to do this in DAX?  Changed quick measures and couldn't find anything relevant.

 

Thanks,

Dan

 

1 ACCEPTED SOLUTION

Hi @dancarr22,

 

Index column is a custom column I created in query edit.

 

Since power bi data model not contains column index and row index, you need one index to let formula calculation dynamic based on current index.(such current -1 or current +1)

 

Date or numeric column can be used as index, text character current not support compare with math symbols.

 

If you only need to calculate on specific source, you can try to use switch function to define them as specific numeric as calculation index.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

HI @dancarr22,


I think you need to add index column based on 'pricing source' column to let formula dynamic.

Sample formula:

Diff =
VAR currIndex =
    MAX ( Table3[Index] )
VAR currPrice =
    CALCULATE (
        SUM ( Table3[Price] ),
        FILTER ( ALLSELECTED ( Table3 ), Table3[Index] = currIndex ),
        VALUES ( Table3[Ticker] ),
        VALUES ( Table3[Date] )
    )
VAR prevPrice =
    CALCULATE (
        SUM ( Table3[Price] ),
        FILTER ( ALLSELECTED ( Table3 ), Table3[Index] = currIndex - 1 ),
        VALUES ( Table3[Ticker] ),
        VALUES ( Table3[Date] )
    )
RETURN
    IF ( prevPrice <> BLANK (), currPrice - prevPrice, currPrice )

12.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi Xiaoxin,

 

Thanks for your assistance with this.

Unfortunately, the solution you provided did not work.

Issue appears to be in the index logic.  while we do have indexes associated with the price source they are not in strict numerical order.  Instead of using "currIndex - 1" is there some other way to define the selected indexes?

If not, can you just provide an example where we do price source 'Bloomberg' vs price source 'Reuters'?  Not the optimal dynamic solution but can go with this for now.

 

Thanks,

Dan

 

Hi @dancarr22,

 

Index column is a custom column I created in query edit.

 

Since power bi data model not contains column index and row index, you need one index to let formula calculation dynamic based on current index.(such current -1 or current +1)

 

Date or numeric column can be used as index, text character current not support compare with math symbols.

 

If you only need to calculate on specific source, you can try to use switch function to define them as specific numeric as calculation index.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks Xiaoxin

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.