Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hi 🙂
I am having trouble calculating the difference between values in the same column.
My dataset is like this:
I added a matrix table based on this data to the dasboard that looks like this:
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? 🙂
Solved! Go to Solution.
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)
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.
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)
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.
Hi @Karlie69 ,
According to your dataset screenshots, the Avr is in the same year of each Part_no, so how to calcualte the difference ?
Best Regards,
Eyelyn Qin
@Anonymous
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.
@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
Hi @amitchandak ,
thanks for your answer. Unfortunately, it doesn't work and I don't know why.
I created the formula like this:
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 47 | |
| 44 | |
| 40 | |
| 18 | |
| 18 |
| User | Count |
|---|---|
| 70 | |
| 68 | |
| 33 | |
| 32 | |
| 32 |