Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Calculate Difference Between Dates in the same Column and the %

 

 

Hi

I am new to Power Bi, I have a problem and hope someone will be so kind to help:

I need to calculate a variance of the Sales (Column C) by Region (Column A) between the two years (Column B)

 

calculate column.PNG

8 REPLIES 8
v-chuncz-msft
Community Support
Community Support

@Anonymous ,

 

You may refer to the following post.

https://community.powerbi.com/t5/Desktop/Students-variations-year-over-year/m-p/345749#M155124

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi

 

Thanks for your reply, but I don't see how this post helps me to resolve my DAX formula issue.

Anonymous
Not applicable

Sorry, clicked on the Post button by accident and don't know how to edit the post.

 

... and I also need to calculate the %.

 

Any help would be greatly appreciated.

Hi,

 

You could try the solution provided here and see if it works for you

How to create variance field and variance %

 

 

Anonymous
Not applicable

Hi

 

Thanks for the link, I used the formula below:

_Sales Variance = CALCULATE(SUM(Data[Sales_value £k]),FILTER(Data,'Data'[fiscal_year]=2018-19))-CALCULATE(SUM(Data[Sales_value £k]),FILTER(Data,'Data'[fiscal_year]=2017-18))
 
But an error message:
MdxScript(Modell) (10 80) Calculation error in measure 'Data'[_sales variance]:DAX comparison operations do not support comparing values of type text with values of type integer. Consider using the Value or Format funciton to convert one of the values.
 
Please Help, I am really struggling. 😞
 

Right, looking at the code the problem here is that the fiscal year is of the data type text because it contains a hyphen.

 

The easiest solution would be either replace your current fiscal year column or create a duplicate fiscal year column and than remove the hyphen and change the datatype to a whole number.

 

In the power query you could just duplicate the column, replace the hyphen with nothing and than convert it to whole number.

Or you could create a custom column and use the following dax code

Column = SUBSTITUTE(Table[YearColumn],"-","")

Just replace the table & column with your own and format it as a whole number under the modeling tab. Then use this new column in the code and it should work.

 

Anonymous
Not applicable

Hi

Thanks for your reply. The variance DAX works now, but Variance % is not:

Sales_Var% = DIVIDE('Data'[_Sales Variance],CALCULATE(sum(Data[Sales_value £k]),FILTER(ALL(Data[FiscalYearNew]=201718)))
 
Too few arguments were passed to the filter function. The mimimum argument count for the function is 2.
 
Any help is greatly appreciated.
 
Anonymous
Not applicable

Spoke too soon, the variance doesn't work, the value in the variance column  is exactly the same as the Sales column.

Please help!!!

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors