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

Calculating a sum column based on two other columns using a filter

Hi Everyone,
I'm trying to create a new column using DAX which sums two other columns using a filter for every month. I have a table which looks like the following:

akkitek_0-1683634072359.png

 

For each month, the column should sum up "Actual Hours to Date" until that month and sum up "Person Hours Booked" for rest of the months.

 

So for example:
For the month of January, the formula is: (106 (Actuals Hours December)+ 160 (Actual Hours January)+ 368 (Forecasted Hours February)+ 423 (March Forecasted Hours) + 368 (April Forecasted Hours) + 423 (May Forecasted Hours)+ 405 (June Forecasted Hours)+ 167 (July Forecasted Hours))
Therefore the rate is $2420. 

For the month of Feb it should sum up actual hours until feb and person hours booked for future months.

The column should only populate until the last month where the Data type = "Actual"

Here's the expected output:

akkitek_0-1683644490594.png

 



Here's the code I've tried but it doesn't seem to work. It seems like this should be easier than this:
System Rate =
IF(FACT_Fin_Data_by_Mo[Data Type] = "Actual",
VAR LastMonthsActualHours = CALCULATE(SUM(FACT_Fin_Data_by_Mo[Actual Hours to Date (Month)]),
FILTER(DIM_Date,
DIM_Date[Date] >= DATEADD(LASTDATE(DIM_Date[Date]), -2, MONTH) &&
DIM_Date[Date] <= LASTDATE(DIM_Date[Date]) &&
FACT_Fin_Data_by_Mo[Data Type] = "Actual"
)
)
RETURN LastMonthsActualHours + FACT_Fin_Data_by_Mo[Actual Hours to Date (Month)],
VAR ProjectedHours = CALCULATE(SUM(Scheduled_Variance[Person Hours Booked]),
FILTER(DIM_Date,
DIM_Date[Date] > LASTDATE(PREVIOUSMONTH(DIM_Date[Date])) &&
FACT_Fin_Data_by_Mo[Data Type] = "Projected"
)
)
RETURN ProjectedHours
)

Any help is appreciated! Thank you!

1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

View solution in original post

7 REPLIES 7
akkitek
Helper III
Helper III

Hi @Ashish_Mathur ,
I have tried a bunch of different measures but to no avail. I'm guessing its got something to do with the data model?

akkitek_0-1683739247696.png

Here's a link to the test file: https://drive.google.com/file/d/1__IMIyQ1TU9Zo2D8U5iY4EQd8RPYzNgC/view?usp=sharing
Any ideas will be super helpful! Thank you!

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

OMG @Ashish_Mathur, you genius! worked like a charm! Always saving the day! Thank you so much!

You are welcome.  Thank you for your kind words.


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

@akkitek Please Share your Expected output in Table formatted.
THANK YOU!!

Hi @Mahesh0016 
Thank you for your reply. 
Here's the expected output in a table format:

akkitek_0-1683644127692.png

Basically I'm looking to add the "actual hours to date" until each month and add "Person hours booked" for future months. Thanks! 

 

@Mahesh0016  Am I doing something wrong with my Data model? 

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.