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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Dynamic Project Cost

Hi,

 

I'm trying to get the Project cost dynamically based on Month and Year.

Below is the sample data.

 

Project IDProject NameStart DateEnd DateMonthly Cost
1A01-01-1931-12-26200000

 

I would like to get the Monthly and Yearly cost dynamically based on the date selected.

 

Any help in writing DAX query would be appreciable.

 

Thank you.

 

Regards,

Prajna

1 ACCEPTED SOLUTION

Hi @Anonymous 

 

Please change the relationship between fact table and employee table and set the cross filter direction is both.

vchenwuzmsft_0-1644544596688.png

Result:

vchenwuzmsft_3-1644544816496.png

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @serpiva64 ,

 

Below is the sample data.

 

Project IDProject Name Start Date End DateMonthly Cost
1A01-01-1931-12-26200000
2B01-06-2105-12-23100000
3C15-04-1818-10-2275000

 

For an instance, if I select the date period from May 2021 to June 2021, I would like to see the below result based on the Start and End Date of the project dynamically.

Project Name Cost 
A400000(200000*2)
B100000(100000*1)
C150000(75000*2)

 

In order to achieve this, I should write a DAX measure as it wont work well with just visuals.

 

Thanks,

Prajna

Hi @Anonymous ,

 

You can try this code:

Cost =
VAR _start =
    IF(
        MIN( 'Calendar'[Date] ) >= SELECTEDVALUE( 'Table'[Start Date] ),
        MIN( 'Calendar'[Date] ),
        SELECTEDVALUE( 'Table'[Start Date] )
    )
VAR _end =
    IF(
        MAX( 'Calendar'[Date] ) <= SELECTEDVALUE( 'Table'[End Date] ),
        MAX( 'Calendar'[Date] ),
        SELECTEDVALUE( 'Table'[End Date] )
    )
VAR _diff =
    IF( _start < _end, DATEDIFF( _start, _end, MONTH ) + 1, 0 )
RETURN
    _diff * SELECTEDVALUE( 'Table'[Monthly Cost] )

Result:

vchenwuzmsft_0-1644381809085.png


Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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 @v-chenyue-msft ,

 

Thanks for the measure.
Although this is what I wanted, the measure doesn't work fine with the columns from other tables.
I have connected the Project table to an Employee table based on Project ID to get the employee details.

 

I would like to see the Project name, respective Employee email and the cost.
Sample below.

Prajna_0-1644489263026.png

Could you kindly suggest on how can the measure work when a column from other tables are got in the table.

 

 

Thanks,

Regards.

 

Hi @Anonymous 

 

Please change the relationship between fact table and employee table and set the cross filter direction is both.

vchenwuzmsft_0-1644544596688.png

Result:

vchenwuzmsft_3-1644544816496.png

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

serpiva64
Solution Sage
Solution Sage

Hi, 

please provide a sample date with just more then 1 row.

To make what you want you don't need writing Power query or Dax, just create visuals

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.