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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
pheukshorst
New Member

Apply a factor to measure based on date range table

I have a date range table by account number with a factor (i.e. the fuel surcharge).

 

AccountNumberdateFromdateToFuel Surcharge(%)
AA1/1/20231/31/20235
BB1/1/20231/31/20236
AA2/1/20232/28/20237
BB2/1/20232/28/2023

8

 

I have a DAX measure called "Cost". 

I want a new "Cost+Fuel" measure that factors in the fuel surcharge based on the account and 

date the transaction occured, but I don't know how to make this happen.

 

Currently I have a relationship on the lookup table's AccountNumber to the transactional data but no relationship on the dateFrom or dateTo columns.

 

Here is what I need the "Cost Plus Fuel" measure to equal.

 

AccountNumberDateCostCost Plus Fuel
AA1/20/2023100105
BB2/20/2023100106
AA1/20/2023100107
BB2/20/2023100108

 

 

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi pheukshorst,

 

Thanks for the sample numbers. I am assuming you meant that the dates in the Cost Plus Fuel table is like as shown in the screen print below instead of two January dates and two February dates for AA and BB Account Numberes respectively.  

Sakiko_0-1693202341431.png

 

With this assumption, I have copied and pasted the rest of the sample data table you've prepared, and created the data model like shown below:

Sakiko_1-1693202700703.png

 

Please note that, only the Cost Plus Fuel table has a relationship with the calendar table, while Fuel Surcharge table with the duration information of the applicable surcharge does not have any relationship with the calender table.  Also, I've created a dimension table for Account Number in order to avoid many-to-many relationship which creates ambiguity and confusion in the data model.  I've then created many-to-one relationships for the Account Number dimension table with the fact tables. 

 

Next, I created a dax measure expression to capture the cost plus percentage for a selected date which falls within the duration range.  

 

Sakiko_4-1693203354210.png

 

 

Next, I've created a calculated column which wraps the measure created above with Calculate function to respect the row context of this table. 

Sakiko_3-1693203164792.png

The result generated is as you have requested.  Please let me know if you'd like to have the pbix file for this task.  

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi pheukshorst,

 

Thanks for the sample numbers. I am assuming you meant that the dates in the Cost Plus Fuel table is like as shown in the screen print below instead of two January dates and two February dates for AA and BB Account Numberes respectively.  

Sakiko_0-1693202341431.png

 

With this assumption, I have copied and pasted the rest of the sample data table you've prepared, and created the data model like shown below:

Sakiko_1-1693202700703.png

 

Please note that, only the Cost Plus Fuel table has a relationship with the calendar table, while Fuel Surcharge table with the duration information of the applicable surcharge does not have any relationship with the calender table.  Also, I've created a dimension table for Account Number in order to avoid many-to-many relationship which creates ambiguity and confusion in the data model.  I've then created many-to-one relationships for the Account Number dimension table with the fact tables. 

 

Next, I created a dax measure expression to capture the cost plus percentage for a selected date which falls within the duration range.  

 

Sakiko_4-1693203354210.png

 

 

Next, I've created a calculated column which wraps the measure created above with Calculate function to respect the row context of this table. 

Sakiko_3-1693203164792.png

The result generated is as you have requested.  Please let me know if you'd like to have the pbix file for this task.  

pheukshorst
New Member

Note: I pasted the tables from excel and didn't notice that the column data isn't separated very well anymore.

The fuel rates in the first table are simply 5, 6, 7 and 8.

The "Cost" in the 2nd table is 100 for all 4 rows.

 

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.