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! Request now

Reply
mai_daftari
Regular Visitor

Problem in calculating Current Month and Previous Month for all Cost Centers

Hello ,

Hope you are doing well.

I am facing a problem is calculating “Current Month Sales” and “Previous Month Sales” for all Cost Centers (Departments), measures are calculating correctly for only one cost center and not for others.

 

Here is the view of matrix where you can easily see that the column “Sales” and “Last month sales” are being calculated correctly for Cost Center "Transport" but not for Cost Center “Trading”, however “revenue_sum” column for both cost centers shows sales correctly.

mai_daftari_0-1725086364645.png

 

I am using following measure for calculating “Revenue_Sum”, “Total monthly Sales” and “Previous month sales”

Revenue_Sum

Revenue_Sum = Sum(VU_GET_ALL_REVENUES[Amount])

 

Sales

Current_Sales_MTD = CALCULATE(sum(VU_GET_ALL_REVENUES[Amount]), DATESMTD('Calendar'[DATE]))

 

Last Month Sales

Previous_Sales_MTD = CALCULATE(SUM(VU_GET_ALL_REVENUES[Amount]) ,  PREVIOUSMONTH(DATESMTD('Calendar'[DATE]))

 

I have also attached relationships image

With the following details

  • VU_GET_ALL_COST_CENTER_GROUPS[cost_center_id]    1 : *   VU_GET_ALL_COST_CENTERS[Group_id]
  • VU_GET_ALL_COST_CENTERS[Cost_center_Id]   1:*   VU_GET_ALL_REVENUES[Cost_Center_Id]
  • Calender[Date]   1:*  VU_GET_ALL_REVENUES[Date_]

mai_daftari_1-1725086958595.png

 

kindly assist where I am making a mistake that’s stopping it from calculating “Current Month” and “Previous Month Sales” for other cost centers  and how to resolve this issue.

I also tried replacing PREVIOUSMONTH and MTD with DateADD in above measures, but did not work

 

 

 

1 ACCEPTED SOLUTION
MattAllington
Community Champion
Community Champion

Is there a reason you're using MTD?  Given you have many months in your visual, the months are completed and hence you may not need MTD. So unless this is to solve some specific reporting issue, I suggest you simplify as follows

Current_Sales = sum(VU_GET_ALL_REVENUES[Amount])
 
Previous_Sales_MTD = CALCULATE(SUM(VU_GET_ALL_REVENUES[Amount]),                              PREVIOUSMONTH('Calendar'[DATE]))

if that doesn't solve the problem, I suggest you creat a new table on a new sheet

add. A. Slicer for cost centre and select the cost centre at issue

place year and month from the calendar table on rows

drag the raw column VU_GET_ALL_REVENUES[Amount] and put it on values. Does it work?  If not, it's not the DAX that is the problem, it's the data. 
add the 2 measures and see if you can spot any issues. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

9 REPLIES 9
MattAllington
Community Champion
Community Champion

Is there a reason you're using MTD?  Given you have many months in your visual, the months are completed and hence you may not need MTD. So unless this is to solve some specific reporting issue, I suggest you simplify as follows

Current_Sales = sum(VU_GET_ALL_REVENUES[Amount])
 
Previous_Sales_MTD = CALCULATE(SUM(VU_GET_ALL_REVENUES[Amount]),                              PREVIOUSMONTH('Calendar'[DATE]))

if that doesn't solve the problem, I suggest you creat a new table on a new sheet

add. A. Slicer for cost centre and select the cost centre at issue

place year and month from the calendar table on rows

drag the raw column VU_GET_ALL_REVENUES[Amount] and put it on values. Does it work?  If not, it's not the DAX that is the problem, it's the data. 
add the 2 measures and see if you can spot any issues. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Thanks MattAllington for the reply.

I just did as said by you, removed MTD and used PREVIOUSMONTH, 

 

Current_Sales = sum(VU_GET_ALL_REVENUES[Amount])
Previous_Sales = CALCULATE(SUM(VU_GET_ALL_REVENUES[Amount]) ,  PREVIOUSMONTH(('Calendar'[DATE]))
 

Now i am able to see current sales but not previous month sales

 

mai_daftari_1-1725090559089.png

 

 

You should have year and month in your visual, not just month.



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Hi @MattAllington ,

 

I even tried that, the result is the same, showing previous month sales of Cost Center "Transport", other cost centers are not displaying previous month sales.

 

 

mai_daftari_0-1725109902312.png

Now just for second opinion, what could be wrong with the data that may cause such behaviour 

 

My start by assumption is there is no matching data. When I face this problem, add the cost centre number from the dim table and also from the fact table into the visual. Probably better to swap it for a table, not a matrix. My guess is there's no data in the fact table that matches the code in the sim table.  



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

Thanks for the reply. while preparing pbix file (removing all other tables except revenue and date and cost centers), the visual started showing results.

It looks like a relationship problem, thanks aneways, image attached.

 

mai_daftari_1-1725197412025.png

 

Hi @mai_daftari ,

 

Out of curiosity, I always thought cost centers were typically used for operating expenses, not for revenues, which are usually assigned to profit centers.

That aside, I attempted to replicate the issue you're describing using some dummy data with blank months, but I couldn't reproduce the problem.

Thank you, MattAllington , for your advice.

Previous_Sales_MTD = CALCULATE( SUM(VU_GET_ALL_REVENUES[Amount]), DATESMTD(PARALLELPERIOD('Calendar'[DATE], -1, MONTH)) )

 

DataNinja777_0-1725092391188.png

Using random data, I tried to recreate the issue you’re experiencing, but I wasn't able to, except for the missing total row for the previous month, which is shown in the second table. The first table uses the modified formula in the code snippet.

 

Best regards,

 

Hi @DataNinja777  , thankyou very much for your effors for re-producing the error. I my self confused as to what is wrong with the data that measures are failing to calculate.

 

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