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
PaulShlapa
Helper I
Helper I

Add change between years as a column to the table

Dear Experts,

 

I have data in a following table

Screenshot 2024-03-01 164801.png

 

 

 

 

 

 

 

What i would like to do is to add another column that would show difference in price for each material between years. It should look like that

Screenshot 2024-03-01 165319.png

Additionally, i would like to create a measure that would calculate difference for each material between years, depending on the selection of the slicer "Year" from the same table.

For example if i choose a period from 2021 to 2024:

A = 4

B = 5

 

Any help would be appreciated.

 

Sincerely,

 

Pavlo

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

Hi  @PaulShlapa ,

 

Thank @amitchandak  for answering the questions and sharing your knowledge, I'm going to add to the first question and answer the second one here.

 

Here are the steps you can follow:

Question1

Create calculated column.

Difference =
var _test=
SUMX(
    FILTER('Table',[Material]=EARLIER([Material])&&[Year]=EARLIER([Year])-1),[Price])
return
IF(
    _test=BLANK(),BLANK(),
    [Price] - _test)

vyangliumsft_0-1709531046848.png

Question2

Create measure.

Measure =
var _mindate=MINX(ALLSELECTED('Table'),[Year])
var _maxdate=MAXX(ALLSELECTED('Table'),'Table'[Year])
var _value1=SUMX(FILTER(ALL('Table'),'Table'[Material]=MAX('Table'[Material])&&'Table'[Year]=_mindate),[Price])
var _value2=SUMX(FILTER(ALL('Table'),'Table'[Material]=MAX('Table'[Material])&&'Table'[Year]=_maxdate),[Price])
return
_value2 - _value1

vyangliumsft_1-1709531046849.png

 

 

Best Regards,

Liu Yang

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

3 REPLIES 3
PaulShlapa
Helper I
Helper I

Many thanks to both of you @amitchandak and @v-yangliu-msft 

v-yangliu-msft
Community Support
Community Support

Hi  @PaulShlapa ,

 

Thank @amitchandak  for answering the questions and sharing your knowledge, I'm going to add to the first question and answer the second one here.

 

Here are the steps you can follow:

Question1

Create calculated column.

Difference =
var _test=
SUMX(
    FILTER('Table',[Material]=EARLIER([Material])&&[Year]=EARLIER([Year])-1),[Price])
return
IF(
    _test=BLANK(),BLANK(),
    [Price] - _test)

vyangliumsft_0-1709531046848.png

Question2

Create measure.

Measure =
var _mindate=MINX(ALLSELECTED('Table'),[Year])
var _maxdate=MAXX(ALLSELECTED('Table'),'Table'[Year])
var _value1=SUMX(FILTER(ALL('Table'),'Table'[Material]=MAX('Table'[Material])&&'Table'[Year]=_mindate),[Price])
var _value2=SUMX(FILTER(ALL('Table'),'Table'[Material]=MAX('Table'[Material])&&'Table'[Year]=_maxdate),[Price])
return
_value2 - _value1

vyangliumsft_1-1709531046849.png

 

 

Best Regards,

Liu Yang

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

amitchandak
Super User
Super User

@PaulShlapa , in case you need a new column

 

Last year = sumx(filter(Table, [Material] = earlier([Material]) && [Year] = earlier([Year]) -1), [Price])

 

 

In case you need a measure,

Previous Year = CALCULATE(sum(Table[Price]),OFFSET(-1, ALL('Table'[Year],'Table'[Material]),ORDERBY('Table'[sort]),KEEP,PARTITIONBY('Table'[Material])))

 

Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

Continue to explore Power BI Offset Compare Categories, Time Intelligence MOM, QOQ, and YOY: https://youtu.be/5YMlkDNGr0U

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.