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
MarcUrdang
Post Patron
Post Patron

variance calculation

Please advise on how to create a variance and a variance % as per below:

I have created two calculations which compute a measure for a period of time. This year to date and last year to date:

 

1. This YTD:   CALCULATE(SUM('Table1'[measures]),DATESYTD((Date'])))

2. Last YTD:   CALCULATE(SUM('Table1'[measures]),DATEADD(FILTER(DATESYTD('Table1'[Date]),'Table1'[Date]<TODAY()),-1,YEAR))

 

I have a table whih show various cities and the above two calcs show the values per city.

For example if CityA had 10 for last YTD and 15 for this YTD then the Variance must show 5 and the % difference would be 50%

 

Thank you

Marc

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@MarcUrdang 

Give this a try.

Variance = DIVIDE ( [This YTD], [Last YTD] ) -1

View solution in original post

5 REPLIES 5
nandukrishnavs
Super User
Super User

@MarcUrdang 

 

Sample dataset

DateCitySales
01-01-2019CityA200
01-02-2019CityA250
01-03-2019CityA300
01-04-2019CityA350
01-05-2019CityA400
01-06-2019CityA450
01-07-2019CityA300
01-08-2019CityA150
01-09-2019CityA175
01-10-2019CityA200
01-11-2019CityA225
01-12-2019CityA250
01-01-2020CityA275
01-02-2020CityA300
01-03-2020CityA325
01-04-2020CityA350
01-05-2020CityA375
01-01-2019CityB150
01-02-2019CityB155
01-03-2019CityB160
01-04-2019CityB165
01-05-2019CityB170
01-06-2019CityB175
01-07-2019CityB180
01-08-2019CityB185
01-09-2019CityB190
01-10-2019CityB195
01-11-2019CityB200
01-12-2019CityB205
01-01-2020CityB210
01-02-2020CityB215
01-03-2020CityB220
01-04-2020CityB225
01-05-2020CityB230

 

 

 

YTD Sales = CALCULATE(SUM('Table'[Sales]),DATESYTD('Table'[Date].[Date]))
Prv YTD Sales = CALCULATE(SUM('Table'[Sales]),DATESYTD(SAMEPERIODLASTYEAR('Table'[Date].[Date])))
YTD difference = [YTD Sales]-[Prv YTD Sales]
Variance % = DIVIDE([YTD difference],[Prv YTD Sales],BLANK())

 

 

Capture.JPG

If you are not using Date Hierarchy, you can remove .[Date] from the above measures.

YTD Sales = CALCULATE(SUM('Table'[Sales]),DATESYTD('Table'[Date]))​
Prv YTD Sales = CALCULATE(SUM('Table'[Sales]),DATESYTD(SAMEPERIODLASTYEAR('Table'[Date]])))

Capture.JPG

Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

amitchandak
Super User
Super User

@MarcUrdang , try like

YTD QTY forced= 
var _max = today()
return
calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),'Date'[Date]<=_max)
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))

LYTD QTY forced= 
var _max = date(year(today())-1,month(today()),day(today()))
return
CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

Hi Amit .. got it to work .. .WOW WOW ... you are a legend!!!!! I get scared to think of does one ever get to be as knowledgeable as someone like you.

 

thank you soooo very much

Hi Amit .. thanks for trying to help. hope all well your side

 

So to clarify:

 

1. My calcs work fine for indiviudal fields

2. To get the difference btw the two I use yours ...  is it once calc? Also why the // this is to make what follows just text?

 

Sorry that i'm a little confused .. can you help clarify?

tx

Marc

jdbuchanan71
Super User
Super User

@MarcUrdang 

Give this a try.

Variance = DIVIDE ( [This YTD], [Last YTD] ) -1

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.