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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Karlie69
Regular Visitor

Difference between values in the same column for unique index

Hi 🙂

I am having trouble calculating the difference between values in the same column.

 

My dataset is like this:

avr.PNG

I added a matrix table based on this data to the dasboard that looks like this:

 

fff.PNG

 

Now I would like to add a column to this table that would calculate the Avr. currency price difference between 2021 and 2020 for each unique Part_no. There are blanks in the data. Unfortunately, I do not know how to write the DAX formula

 

Anyone know the answer? 🙂

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @Karlie69 ,

 

difff = 
var _pre=CALCULATE(SUM('Table'[Avr]),FILTER('Table',[Part_no]=EARLIER('Table'[Part_no]) && [Year]=EARLIER([Year])-1))
return  IF(_pre=BLANK(),BLANK(), [Avr]-_pre)

Eyelyn9_0-1637894729897.png

Eyelyn9_1-1637894741453.png

 

 

If it's not your expected output, please share more detail information to help us clarify your scenario.

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-eqin-msft
Community Support
Community Support

Hi @Karlie69 ,

 

difff = 
var _pre=CALCULATE(SUM('Table'[Avr]),FILTER('Table',[Part_no]=EARLIER('Table'[Part_no]) && [Year]=EARLIER([Year])-1))
return  IF(_pre=BLANK(),BLANK(), [Avr]-_pre)

Eyelyn9_0-1637894729897.png

Eyelyn9_1-1637894741453.png

 

 

If it's not your expected output, please share more detail information to help us clarify your scenario.

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you very much! It works 🙂 I just changed the formula from SUM to AVERAGE, because in some places I had bad results, but now it's good everywhere.

v-eqin-msft
Community Support
Community Support

Hi @Karlie69 ,

 

According to your dataset screenshots, the Avr is in the same year of each Part_no, so how to calcualte the difference ?

Eyelyn9_0-1637820583307.png

 

Best Regards,
Eyelyn Qin

@v-eqin-msft 

Sorry, this is my mistake. For the purposes of this post, I created an example dataset. The fourth line should be 2021.

 

I would just like to add a calculated column like in Excel pivot tables that will calculate the difference for me between 2021 and 2020. But is it better to make a pivot table in Power Query and calculate the difference there?

I did not think about it before - even if I create this column with DAX, it will not appear next to 2020 and 2021 in the table, but under these years.

amitchandak
Super User
Super User

@Karlie69 , Try new column like

 

New column =
var _max = maxx(filter(Table, [part number] = earlier([part number]) && [year] = earlier([year]) -1), [Avr. Currency Price])
return
[Avr. Currency Price] -_max

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak ,

 

thanks for your answer. Unfortunately, it doesn't work and I don't know why.

I created the formula like this:

Capture789.PNG

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.