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
Anonymous
Not applicable

Calculate cost per mile by Total Cost for each given year

Hello! I am trying to create a measure that can calculate the cost per mile for each type of category from the total cost (labor + materials) for each given year. How would this be possible? Thanks in advance

 

CategoryMiles
Natural Surface201.0
Hard Surface68.6

 

costpermile.PNG

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Don'@mrmiyagi,

You can try using the following formal calculation table to dsiplay summary results:

Detail Table =
ADDCOLUMNS (
    SUMMARIZE (
        ADDCOLUMNS ( ALLSELECTED ( Table ), "Year", YEAR ( [Date] ) ),
        [Year],
        [Asset Category],
        "Count", COUNT ( Table[Asset Category] ),
        "T_labor", SUM ( Table[Labor Cost] ),
        "T_Materials", SUM ( Table[Labol_Materials] )
    ),
    "Cost_Per_Miles",
        DIVIDE (
            [T_labor] + [T_Materials],
            [Count]
                * SWITCH ( [Asset Category], "Natural Surface", 201.0, "Hard Surface", 68.6 )
        )
)

Best regards
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Don'@mrmiyagi,

You can try using the following formal calculation table to dsiplay summary results:

Detail Table =
ADDCOLUMNS (
    SUMMARIZE (
        ADDCOLUMNS ( ALLSELECTED ( Table ), "Year", YEAR ( [Date] ) ),
        [Year],
        [Asset Category],
        "Count", COUNT ( Table[Asset Category] ),
        "T_labor", SUM ( Table[Labor Cost] ),
        "T_Materials", SUM ( Table[Labol_Materials] )
    ),
    "Cost_Per_Miles",
        DIVIDE (
            [T_labor] + [T_Materials],
            [Count]
                * SWITCH ( [Asset Category], "Natural Surface", 201.0, "Hard Surface", 68.6 )
        )
)

Best regards
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

 

Thanks for the response! I already have a table 'Attributes' which has the mileage and will be further expanded with more classes. I tried it a different way but it seems like something is missing as I should get the same amount if I mulitply Size x CPM (cost per mile) but thats not the case. Is this because I need to include some time intelligence? 

 

Selecting one year yeilds 465.32 CPM for "Natural Surface Trail" 

465.32 x 201 = 93,529.32

The total sum for Natural Surface Trail is 125,405.04

powerbi_cpm.PNG

 

SumLabor_Materials = SUM('Booked Labor'[Labor Cost]) + SUM('Booked Materials'[Material Cost])

Sum_Size = SUM('Attributes'[Size])

CPM = DIVIDE([SumLabor_Materials],[Sum_Size])

 

HI @Anonymous,

It sounds like a common multiple aggregates calculations issue on the total level, you can take a look at Greg's blog to know more about how to solve this:

Measure Totals, The Final Word 
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.