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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
scotjn1
Helper I
Helper I

need a measure to divide, but with different denominators depending on the dimension value

I have vehicle cost and mileage data in my data model.  The costs are broken out by category, and I'm trying to create a measure to calculate cost-per-mile based on total miles driven, similar to the image below.

 

image002.jpg

 

The sticking point is that my denominator is different depending on the category being calculated.  I have measures that calculate how many miles "contributed" to the costs in each particular category.

 

image003.jpg

 

For example, the cost-per-mile for the "Fuel Charges" category above should be based on the _FuelMilesBill immediately above, while the "Lease Expense" category should be divided by _DeprMiles.

 

Intuitively, this would be a simple IF statement, but I cannot seem to access "billing[charge category]" (or any other text field) as the LogicalTest part of my IF function.  Conceptually speaking, a simplified version of the measure would be something like this:

 

= SUM(billing[bill_amt]) / if(charge_code_group[charge category]="Fuel Charges",[_FuelMiles],if(charge_code_group[charge category]="Lease Charges",[_DeprMiles],[_UnitMiles]))

I can get the respective mileages to show up in the table, so I know all the data can "see" each other, but I cannot get it to the next level where the cents-per-mile math is applied to the appropriate denominator.

 

image004.jpg

 

In case it matters, my billing and mileage tables are joined through a key table, where the keys are defined at a vehicle-month level.  (There are many other tables in the data model, but they are unrelated to this problem.)

 

image006.jpg

 

There's also an enrollment table, defined at a vehicle-month level, which identifies with 1/0 if a vehicle is on a given program or not.  This is 1/0 flag is used to determine the mileages associated with each program.  The structure of the enrollment table is shown here:

 

image005.jpg

 

In full transparency, this is an example of how the "_XXXMiles" measures are written:

 

_DeprMiles = CALCULATE(SUM('estimates'[Est Miles]),enrollment[LeaseMonths]=1,all(charge_code_group[charge category]))

I've been scratching my head and googling for ideas for two days, but I'm not closer than I was when I started.  Any help would be much appreciated!

 

Thanks,

Jacob

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi @scotjn1,

 

Does this work

 

=IF(HASONEVALUE(charge_code_group[charge category]),SUM(billing[bill_amt]) / if(VALUES(charge_code_group[charge category])="Fuel Charges",[_FuelMiles],if(VALUES(charge_code_group[charge category])="Lease Charges",[_DeprMiles],[_UnitMiles])),BLANK())


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

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi @scotjn1,

 

Does this work

 

=IF(HASONEVALUE(charge_code_group[charge category]),SUM(billing[bill_amt]) / if(VALUES(charge_code_group[charge category])="Fuel Charges",[_FuelMiles],if(VALUES(charge_code_group[charge category])="Lease Charges",[_DeprMiles],[_UnitMiles])),BLANK())


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

Thank you!  This has done the trick, and has provided the foundation for this table.  Now if only i could get them to total at the bottom...  Smiley Happy  It doesn't look like the HASONEVALUE function will allow for that.  Oh, well.  This is good stuff!

 

image007.jpg

You are welcome.  Let me know what figure you are expecting to see in the Grand Total row.  Also, share the link from where i can download your file.


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

I'm thinking that if you are going for a measure, then you will need to do an aggregation on your category like LASTNONBLANK or FIRSTNONBLANK.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.