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
QaziArfeen
Frequent Visitor

Calculate cost based on date ranges

I have an issue which I need help with.

I have a table "Hourly Rates" which has hourly rates for employees with start and end date. This table will track all the hourly rates with start and end dates

Example

hourlyrates.png

 

I have Tasks table which tracks tasks done by employees and how much time it took them. This table also has task performed date

Example

Tasks.png

Rates in Hourly rates are per hour and Duration in Tasks table in minutes.

 

We already have a relation between Employee Code and all the date columns are formatted. Above example is for illustration only. What I am looking for is the following in PowerBI. It does not matter if we create a custom column or a measure or a new table all together.

Cost.png

It is very obvious that I am looking to calculate COST depending on the date the task was performed and what were the hourly rates when the task was performed.

 

 

 

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @QaziArfeen

 

Add this calculated column in Tasks Table to get the Cost

 

Cost =
VAR Rate =
    CALCULATE (
        VALUES ( HourlyRates[Rates] ),
        FILTER (
            HourlyRates,
            Tasks[Employee Code] = HourlyRates[Employee Code]
                && Tasks[Task Performed On] >= HourlyRates[Start Date]
                && Tasks[Task Performed On] <= HourlyRates[End Date]
        )
    )
RETURN
    ROUND ( Tasks[Duration] * Rate / 60, 2 )

Regards
Zubair

Please try my custom visuals

View solution in original post

3 REPLIES 3
BURAIDO
Regular Visitor

I have a similar problem and the solution given seems fine. But my question is the following:

How did you join both tables? It seems that it's a many-to-many relationship if you have the Employee Code several times in both tables... 

Zubair_Muhammad
Community Champion
Community Champion

Hi @QaziArfeen

 

Add this calculated column in Tasks Table to get the Cost

 

Cost =
VAR Rate =
    CALCULATE (
        VALUES ( HourlyRates[Rates] ),
        FILTER (
            HourlyRates,
            Tasks[Employee Code] = HourlyRates[Employee Code]
                && Tasks[Task Performed On] >= HourlyRates[Start Date]
                && Tasks[Task Performed On] <= HourlyRates[End Date]
        )
    )
RETURN
    ROUND ( Tasks[Duration] * Rate / 60, 2 )

Regards
Zubair

Please try my custom visuals

Thank you @Zubair_Muhammad it worked perfectly

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.