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
harshadrokade
Post Partisan
Post Partisan

Create a new column to get the % change in current & previous year

Hi friends,

 

I have table as below-

 

Original table

Student nameperiodendsonABCD
XYZ131-12-201957804437
XYZ131-12-202033513921
XYZ131-12-202126784837
XYZ231-12-201953275761
XYZ231-12-202060705469
XYZ231-12-202129436674
XYZ331-12-201939557334
XYZ331-12-202031654266
XYZ331-12-202173314879
XYZ431-12-201969505730
XYZ431-12-202072776268
XYZ431-12-202143507031

 

I want to create a table visual like below with Change column newly created(with dax). Can u pls help me to know how can I create the same?

 

Expected visual-

Parameter201920202021Change in 2021 compared to 2020
A573326-21%
B80517853%
C44394823%
D37213776%

 

One way is that I unpivot the original table & then it reflects in below format which allows me to create a matrix table in required format. Now I am unable to understand how to add a change column in the table visual as explained above in the visual. Appreciate your help sir.

 

Univot table-

Student nameperiodendsonParameterValues
XYZ131-12-2019A57
XYZ131-12-2019B80
XYZ131-12-2019C44
XYZ131-12-2019D37
XYZ131-12-2020A33
XYZ131-12-2020B51
XYZ131-12-2020C39
XYZ131-12-2020D21
XYZ131-12-2021A26
XYZ131-12-2021B78
XYZ131-12-2021C48
XYZ131-12-2021D37
XYZ231-12-2019A53
XYZ231-12-2019B27
XYZ231-12-2019C57
XYZ231-12-2019D61
XYZ231-12-2020A60
XYZ231-12-2020B70
XYZ231-12-2020C54
XYZ231-12-2020D69
XYZ231-12-2021A29
XYZ231-12-2021B43
XYZ231-12-2021C66
XYZ231-12-2021D74

 

 

 

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

Hi, @harshadrokade 

 

I created a sample to meet your needs.

  • First of all, the Univot table is required.
  • Create a column to flag the last three year data in your matrix table and use it in filter pane.
    (Since I don't know why it's not 2022, I let maxyear -1, You can modify it according to what you want)
Column =
VAR maxyear =
    YEAR ( TODAY () ) - 1
VAR minyear = maxyear - 2
RETURN
    IF (
        YEAR ( [periodendson] ) >= minyear
            && YEAR ( [periodendson] ) <= maxyear,
        1,
        0
    )

vjaneygmsft_0-1643102007848.png

  • Create a measure and use it in meatrix vlaue to show results.

I calculate the sum of the current year and the comparison data separately according to your needs, and force the sum format to remain unchanged, otherwise it will be unified into a percentage format.

Measure =
VAR maxyear =
    YEAR ( TODAY () ) - 1
VAR minyear = maxyear - 1
RETURN
    IF (
        YEAR ( SELECTEDVALUE ( 'Table'[periodendson] ) ) = BLANK (),
        DIVIDE (
            CALCULATE ( SUM ( 'Table'[Value] ), YEAR ( 'Table'[periodendson] ) = maxyear )
                - CALCULATE ( SUM ( 'Table'[Value] ), YEAR ( 'Table'[periodendson] ) = minyear ),
            CALCULATE ( SUM ( 'Table'[Value] ), YEAR ( 'Table'[periodendson] ) = minyear )
        ),
        FORMAT ( SUM ( 'Table'[Value] ), "General Number" )
    )
  • Change some formats.

Results:

vjaneygmsft_1-1643102310669.png

Below is my sample.

 

Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

Best Regards,
Community Support Team _ Janey

 

View solution in original post

3 REPLIES 3
v-janeyg-msft
Community Support
Community Support

Hi, @harshadrokade 

 

I created a sample to meet your needs.

  • First of all, the Univot table is required.
  • Create a column to flag the last three year data in your matrix table and use it in filter pane.
    (Since I don't know why it's not 2022, I let maxyear -1, You can modify it according to what you want)
Column =
VAR maxyear =
    YEAR ( TODAY () ) - 1
VAR minyear = maxyear - 2
RETURN
    IF (
        YEAR ( [periodendson] ) >= minyear
            && YEAR ( [periodendson] ) <= maxyear,
        1,
        0
    )

vjaneygmsft_0-1643102007848.png

  • Create a measure and use it in meatrix vlaue to show results.

I calculate the sum of the current year and the comparison data separately according to your needs, and force the sum format to remain unchanged, otherwise it will be unified into a percentage format.

Measure =
VAR maxyear =
    YEAR ( TODAY () ) - 1
VAR minyear = maxyear - 1
RETURN
    IF (
        YEAR ( SELECTEDVALUE ( 'Table'[periodendson] ) ) = BLANK (),
        DIVIDE (
            CALCULATE ( SUM ( 'Table'[Value] ), YEAR ( 'Table'[periodendson] ) = maxyear )
                - CALCULATE ( SUM ( 'Table'[Value] ), YEAR ( 'Table'[periodendson] ) = minyear ),
            CALCULATE ( SUM ( 'Table'[Value] ), YEAR ( 'Table'[periodendson] ) = minyear )
        ),
        FORMAT ( SUM ( 'Table'[Value] ), "General Number" )
    )
  • Change some formats.

Results:

vjaneygmsft_1-1643102310669.png

Below is my sample.

 

Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

Best Regards,
Community Support Team _ Janey

 

ALLUREAN
Solution Sage
Solution Sage

Hi, @harshadrokade 

You can try this example:

https://www.dropbox.com/s/d070ytj1309cokn/%25%20change%20in%20current%20%26%20previous%20year%20%28a...

 

Did I answer your question? Please Like and Mark my post as a solution if it solves your issue. Thanks.

Appreciate your Kudos !!!

https://allure-analytics.com/

https://www.youtube.com/channel/UCndD_QZVNB_JWYLEmP6KrpA

https://www.linkedin.com/company/77757292/




Did I answer your question? Mark my post as a solution!


https://allure-analytics.com/
https://www.youtube.com/channel/UCndD_QZVNB_JWYLEmP6KrpA
https://www.linkedin.com/company/77757292/

Proud to be a Super User!




Thanks @ALLUREAN  Sir.

 

In Option 2, I can see that te measures you have created is a static measure which provides the value for only 2019, 2020 & 2021 but if the new data gets added for upcoming years to the original data, my table visual will not get updated.

 

Also in Option 1, it works when I have a slicer on the screen. I don't have a slicer on dashbaord & so I want to always show current + last 2 years values from the database.

 

How can I create a visual that will always show me the last three years in table & will show the change in latest year as compared to previous year. Sorry for not putting this requirement earlier. 

 

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.