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
DaGemsta
Helper I
Helper I

Calculate Truck costs from a list of orders using a lookup table

Afternoon all!

 

I'm struggling to get this to work and wondered if anyone can help please?

 

I have two tables.

 

ORDERS

FLEETMASTERLIST

 

ORDERS[Truck] has a Many:1 relationship with FLEETMASTERLIST[Fleet Name.2]

 

The list of ORDERS has the Document Number, Delivery Date, Location (Depot) and Truck for each order that goes out.

My FLEETMASTERLIST table shows me all the Truck information for our 56 vehicles. This includes their "Truck Daily Cost" which is a wholenumber entered manually by the Transport manager.

 

The Truck Daily Cost needs to be counted ONCE per day for each Truck that show on orders for that day. So a truck may show on 6 orders on the 1st of Nov, but the Cost for that Truck is only counted once. If the truck is on 6 orders for the 1st Nov and 3 orders on the 2nd Nov then the Truck Cost would be counted Twice (once per day)

 

Here's some sample date

 

ORDERS

 

Document NumberLocationTruckDelivery Date
SO0185615Grays EU66 SYO01/11/2021 00:00
SO0185656Grays EU66 SYO01/11/2021 00:00
SO0185845Grays EU66 SYO01/11/2021 00:00
SO0187040Grays EU66 SYO01/11/2021 00:00
SO0187081Grays EU66 SYO01/11/2021 00:00
SO0187400Grays EU66 SYO01/11/2021 00:00
SO0183498Grays EU67 ZPZ01/11/2021 00:00
SO0185359Grays EU67 ZPZ01/11/2021 00:00
SO0187002Grays EU67 ZPZ01/11/2021 00:00
SO0187054Grays EU67 ZPZ01/11/2021 00:00
SO0181495Grays EJ19 VYG01/11/2021 00:00
SO0181497Grays EJ19 VYG01/11/2021 00:00
SO0182954Grays EJ19 VYG01/11/2021 00:00
SO0185604Grays EJ19 VYG01/11/2021 00:00
SO0185991Grays EJ19 VYG01/11/2021 00:00
SO0186012Grays EJ19 VYG01/11/2021 00:00
SO0186645Grays EJ19 VYG01/11/2021 00:00
SO0186698Grays EJ19 VYG01/11/2021 00:00
SO0184875Grays EU18 YLX01/11/2021 00:00
SO0185499Grays EU18 YLX01/11/2021 00:00
SO0186323Grays EU18 YLX01/11/2021 00:00
SO0186727Grays EU18 YLX01/11/2021 00:00
SO0186872Grays EU18 YLX01/11/2021 00:00
SO0187113Grays EU18 YLX01/11/2021 00:00
SO0182724Grays GO21 HVO01/11/2021 00:00
SO0182738Grays GO21 HVO01/11/2021 00:00
SO0182787Grays GO21 HVO01/11/2021 00:00
SO0182813Grays GO21 HVO01/11/2021 00:00
SO0182837Grays GO21 HVO01/11/2021 00:00
SO0182852Grays GO21 HVO01/11/2021 00:00

 

 

FLEETMASTERLIST

Fleet Name.1Fleet Name.2Fleet Truck Daily Cost
Grays EU66 SYO£815
Grays EU67 ZPZ£815
Grays EJ19 VYG£850
Grays EU18 YLX£850
Grays GO21 HVO£850

 

How do I create a measure to give me the list of the "Fleet Truck Daily Cost" for the orders that day or for a range of days?

The example for the above Delivery Date should give me a Total for the Depot Grays of £4180.

 

We have many more Depots and many more Trucks so this would need to work for all orders across multiple dates.

 

I just can't seem to get the lookup working.

Help please!

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

Hi @DaGemsta ,

 

Calculate total cost of the special day or a range date.

Please try this code:

Measure =
VAR _S =
    SUMMARIZE (
        ORDERS,
        [Truck],
        [Delivery Date],
        FLEETMASTERLIST[Fleet Truck Daily Cost]
    )
RETURN
    SUMX ( _S, [Fleet Truck Daily Cost] )

 

Result:

vchenwuzmsft_0-1646815077886.pngvchenwuzmsft_1-1646815170999.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

2 REPLIES 2
v-chenwuz-msft
Community Support
Community Support

Hi @DaGemsta ,

 

Calculate total cost of the special day or a range date.

Please try this code:

Measure =
VAR _S =
    SUMMARIZE (
        ORDERS,
        [Truck],
        [Delivery Date],
        FLEETMASTERLIST[Fleet Truck Daily Cost]
    )
RETURN
    SUMX ( _S, [Fleet Truck Daily Cost] )

 

Result:

vchenwuzmsft_0-1646815077886.pngvchenwuzmsft_1-1646815170999.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.

MFelix
Super User
Super User

Hi @DaGemsta 

 

Try to create the following measure:

 

Total cost = 
var temp_table = summarize( Orders, FLEETMASTERLIST[Fleet Name.2],FLEETMASTERLIST[Fleet Truck Daily Cost])
return
SUMX( temp_table , FLEETMASTERLIST[Fleet Truck Daily Cost])

MFelix_0-1646656273450.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.