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
kcantor
Community Champion
Community Champion

Create a measure/calculated field

Greetings,

As a new PowerBI user, I am struggling wtih what is probably a simple DAX statement. Of course I have not successfully integrated this into PowerPivot either so all helap is appreciated.

In my current data, I have a field called TotalSales. When using this in the pivot table or in BI, I use the sum of total sales as the value and order year as columns. Rows vary by the type of information I am seeking. I use order week, category, and manufacturer as some examples for row lables.

What I need is a DAX formula to calculate a $variance and a % variance. In a pivot table, I can simply work outside the table and calculate the difference. IE: 2015Total Sales - 2014 Totals Sales, using cel references. This would return the $Variance. For the % variance, I use an IF statement: =IF(C7=0,"0",((D7-C7)/C7)) with C referencing 2014 sales and D referencing 2015 sales.

I am looking for a course in DAX but need a quick fix for this question. Can anyone here help me come up with a statement for these that would work in both tables?

Relevant Information:

Table Name: SalesPerformance Table

SalesTotals

OrderYear

Kind regards,

KCantor





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

Proud to be a Super User!




1 ACCEPTED SOLUTION
vlahoz
Frequent Visitor

Hello,

 

Create a measure with CALCULATE(SUM([Sales Totals]), SAMEPERIODLASTYEAR([DateColumn])), and then, calculate the variance and %.

 

Vicenç Lahoz

View solution in original post

3 REPLIES 3
vlahoz
Frequent Visitor

Hello,

 

Create a measure with CALCULATE(SUM([Sales Totals]), SAMEPERIODLASTYEAR([DateColumn])), and then, calculate the variance and %.

 

Vicenç Lahoz

Is there any way to accomplish ^ when in direct query mode? Currently Power BI does not support PREVIOUSXXXXX, or LASTXXXX time look backs in direct query.

 

I would switch to import, but the data set is millions of rows and not really feasible to be an import.

Greg_Deckler
Super User
Super User

Not sure of your exact data layout without example data.

 

Have a look here:

http://www.daxpatterns.com/time-patterns/

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors
Top Kudoed Authors