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

Difference and Percentage calculations as per the selected year slicer in power bi report

Hi Team,

 

Could anyone can able to help me to resolve the below isssue 
i had data which need to calculate differences and Percentage based  on the Year filter on slicer 
How many are selected in slicer we need to calculate differences and Percentage

For Example:
if the User selected  year 2020 and 2021 in the slicer we should get differences and Percentage for thsi two years .If again user selected year 2022 then calculation shoulld be done for year 2021 and 2022 on the same column itself , please find the below 
screen shot example for your references 

Venkatesan_0-1656757151498.png

 

 

 

 

 

 

 

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

it is for creating a measure.

 

Untitled.png

 

difference percent vs previous year: = 
VAR _currentvalue = [Value total:]
VAR _previousyearvalue =
    CALCULATE ( [Value total:], Data[Year] = MAX ( Data[Year] ) - 1 )
RETURN
    IF (
        HASONEVALUE ( Data[Year] ) && HASONEVALUE ( Data[ValueType] ),
        DIVIDE ( _currentvalue - _previousyearvalue, _previousyearvalue )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Hi Jihwan_Kim,

Thanks for your quick response but the solution i need 

I have a year slicer which contain quarter,year in this format(Q1,2021) (Q2,2022) ... (Q1,2021) 
i had put in the slicer visual .Now if the User select the year for example Q1,2020 , Q1,2021 , Q2,2022
below the according the year user selected the value will be displayed as shown in the below image 

Venkatesan_0-1656761891868.png

User has been select 3 quarter data in slicer visual ,Now i need to get the differences between three quarter 
like Q1,2021 - Q3,2021 should be first result and then Q3,2021 - Q1-2022 should be second result 
I should get result in this format 

year              SectionA 
q1,2021        1822
q3,2021         1414
q1,2022         1495

result 1 b/w q1,2021 - q3,2021 = 408
result 2 b/w  q3,2021 - q1,2022 = -81

 same if the user selects different year the result should be as first value - second value = result and
second value - third values on the same column on three different rows


Anonymous
Not applicable

Hi ,

I can able to get  the result using this measure

var MaxYear = MAX(Query2[Year])
var MinYear = MIN(Query2[Year])
Return
CALCULATE(sum(Query2[A]),Query2[Year]= MaxYear)-CALCULATE(sum(Query2[A]),Query2[Year]= MinYear).

But if the user chooses the next Q1,2019  i cant able to acheieve the output 
could you please help me to achieve it dynamically 
So that whenever the user select the slicer we should get the result has first value - second value and 
second value - third value 
 

 

Hi @Anonymous,

Can you please share a pbix or some dummy data that keep raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help 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.