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
avulasandeep
Helper III
Helper III

Percentage Difference of Sales for Selected years only

Hi all ,

 

Here is my Question again ,

 

i am getting year over year % Difference by using Quick measure or Dax calculations. But my question is , if I select years randomly from the slicers it is displaying on the previous year difference only not with the selected years as shown in below images.

 

everything i need is to calculate the year over year difference on the selected year from slicers , and if all years selected it has to display the previous year difference.

 

 

img 1.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

img 2.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

from above screenshot :

 

i need selected year over year percentage diff .

 

Anyone if you get the dax calculations for selected years with previous selected years percentage difference, Please let me know .

waiting......

 

 

Thanks 

sandeep 
9441181581

4 REPLIES 4
ryan_mayu
Super User
Super User

@avulasandeep

 

Please try the coding below to see if this can match your requirement. Thanks

 

test1 =

VAR MAXDATE=MAX(Sheet3[year])
VAR maxamount=CALCULATE([totalamount],FILTER(Sheet3,Sheet3[year]=MAXDATE))
VAR Secondmaxdate=MAXX(FILTER(ALLSELECTED(Sheet3),Sheet3[year]<MAXDATE),Sheet3[year])
VAR secondmaxamount=CALCULATE([totalamount],FILTER(ALLSELECTED(Sheet3),(Sheet3[year])=Secondmaxdate))
RETURN
if(ISBLANK(secondmaxamount)," ",DIVIDE(maxamount-secondmaxamount,secondmaxamount))
 
screenshot1.JPGscreenshot2.JPG
 
screenshot1.JPGscreenshot2.JPG




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

Proud to be a Super User!




Kristjan76
Responsive Resident
Responsive Resident

Hi there,

I would try something like (I have not tried this):

total YoY% =
VAR currentYear = Dates[Year]
VAR preYear = 
  CALCULATE(
    MAX(Dates[Year]), 
    ALLSELECTED(Dates[Year]), 
    Dates[Year] < currentYear 
)
RETURN
[total] / CALCULATE(total; Dates[Year] = preYear) - 1

Regars,
Kristjan76

@Kristjan76

This measure is not working fine , please let me know any another measure.

 

 

 

Thanks 

sandeep

You are right it was not working, you can try this one:

total YoY% =
VAR currentYear = IF(HASONEVALUE(Dates[Year]),VALUES(Dates[Year]))
VAR yrs = ALLSELECTED(Dates[Year])
VAR preYear = 
  MAXX(
    FILTER(
      yrs, 
      Dates[Year] < currentYear
    ),
    Dates[Year]
)
VAR res = DIVIDE([total] , CALCULATE([total], Dates[Year] = preYear)
RETURN
IF(NOT(ISBLANK(res)), res - 1)

Regards,

Kristjan

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.