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
Anonymous
Not applicable

calculate percentage different of total amount between two years

Hi, sorry im new to power BI. i tried to calculate the percentage different of totalamount between two years but failed.

steps that i had performed.

1) edit queries, i have 3 columns( monthname,totalamount,year), i pivot monthname with totalamount.

2) in the table result when i select the these three columns it will show as below

Capture.JPG

3) how can i insert the formula to calculate the percentange different of totalamount between this two years and show the result in new row ?

 

expected output. 

 

year   | september    |  october

2018     RM267068     RM677855

2019     RM1205141   RM968686

Diff.                3.512            0.42

Total     RM1,205141   RM968.686

 

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

@Anonymous ,

 

In query editor, click september and october, then click "unpivot", after apply&close like below:

1.PNG

 

Then create a calculate column using dax below:

diff = 
VAR Current_Year = 'Table'[year]
VAR Previous_Year = Current_Year - 1
RETURN
    SWITCH (
        'Table'[Attribute],
        "september", (
            CALCULATE (
                MAX ( 'Table'[Value] ),
                FILTER (
                    'Table',
                    'Table'[Attribute] = "september"
                        && 'Table'[year] = Current_Year
                )
            )
                - CALCULATE (
                    MAX ( 'Table'[Value] ),
                    FILTER (
                        'Table',
                        'Table'[Attribute] = "september"
                            && 'Table'[year] = Previous_Year
                    )
                )
        )
            / CALCULATE (
                MAX ( 'Table'[Value] ),
                FILTER (
                    'Table',
                    'Table'[Attribute] = "september"
                        && 'Table'[year] = Previous_Year
                )
            ),
        "october", (
            CALCULATE (
                MAX ( 'Table'[Value] ),
                FILTER (
                    'Table',
                    'Table'[Attribute] = "october"
                        && 'Table'[year] = Current_Year
                )
            )
                - CALCULATE (
                    MAX ( 'Table'[Value] ),
                    FILTER (
                        'Table',
                        'Table'[Attribute] = "october"
                            && 'Table'[year] = Previous_Year
                    )
                )
        )
            / CALCULATE (
                MAX ( 'Table'[Value] ),
                FILTER (
                    'Table',
                    'Table'[Attribute] = "october"
                        && 'Table'[year] = Previous_Year
                )
            )
    )

2.PNG 

 

Community Support Team _ Jimmy Tao

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

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

What result would you expect when you have more than 2 years of data?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

In query editor, click september and october, then click "unpivot", after apply&close like below:

1.PNG

 

Then create a calculate column using dax below:

diff = 
VAR Current_Year = 'Table'[year]
VAR Previous_Year = Current_Year - 1
RETURN
    SWITCH (
        'Table'[Attribute],
        "september", (
            CALCULATE (
                MAX ( 'Table'[Value] ),
                FILTER (
                    'Table',
                    'Table'[Attribute] = "september"
                        && 'Table'[year] = Current_Year
                )
            )
                - CALCULATE (
                    MAX ( 'Table'[Value] ),
                    FILTER (
                        'Table',
                        'Table'[Attribute] = "september"
                            && 'Table'[year] = Previous_Year
                    )
                )
        )
            / CALCULATE (
                MAX ( 'Table'[Value] ),
                FILTER (
                    'Table',
                    'Table'[Attribute] = "september"
                        && 'Table'[year] = Previous_Year
                )
            ),
        "october", (
            CALCULATE (
                MAX ( 'Table'[Value] ),
                FILTER (
                    'Table',
                    'Table'[Attribute] = "october"
                        && 'Table'[year] = Current_Year
                )
            )
                - CALCULATE (
                    MAX ( 'Table'[Value] ),
                    FILTER (
                        'Table',
                        'Table'[Attribute] = "october"
                            && 'Table'[year] = Previous_Year
                    )
                )
        )
            / CALCULATE (
                MAX ( 'Table'[Value] ),
                FILTER (
                    'Table',
                    'Table'[Attribute] = "october"
                        && 'Table'[year] = Previous_Year
                )
            )
    )

2.PNG 

 

Community Support Team _ Jimmy Tao

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

 

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.