Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
Hi, I am new to DAX, and this is a little beyond me for now.
I am trying to write a job costing report in Power BI, but I don't have any access to the data model. I can create measures, but the report is using a Live connection, and I can't make any changes to it.
I have a transaction table (12 million rows) that I need to reference back based on a custom field in the transaction to get the job cost. The transaction has a job number that I group the revenue by an Item ID. The transaction includes a custom field that contains a PO Number that I then need to go back into the table to retrieve the costs.
sample data
I used ChatGPT to come up with this which gives a result but is very slow (18 secs) to update the visual. Any idea on how to do this efficiently?
Job Cost =
SUMX(
SUMMARIZE(
'Transaction Lines',
'Transaction lines'[Document Number],
'Transaction lines'[Item Internal ID],
"AmountSum",
CALCULATE(
('Transaction Lines'[Amount]),
FILTER(
ALL('Transaction Lines'),
'Transaction Lines'[Document Number] =
MAXX(
VALUES('Transaction Lines'[Logistics Kitting Job Costing PO#]),
RIGHT('Transaction Lines'[Logistics Kitting Job Costing PO#], 18)
)
&& 'Transaction Lines'[Item Internal ID] = MAX('Transaction Lines'[Item Internal ID])
)
)
),
[AmountSum]
)
Sample visual
Thanks
Steve
Hello Steve,
I understand that you're trying to optimize your DAX measure for calculating the job cost in Power BI, especially since you're working with a large dataset (12 million rows) and have limitations due to the live connection. Let's work through a more efficient way to achieve your goal.
From your description:
Document Number
: Identifies each transaction.Item Internal ID
: The item identifier.Amount
: The transaction amount.Logistics Kitting Job Costing PO#
: Contains the PO Number, from which you extract the rightmost 18 characters.You need to sum the Amount
for transactions where:
Document Number
matches the PO Number extracted from Logistics Kitting Job Costing PO#
.Item Internal ID
matches.Your current measure is slow because:
FILTER(ALL('Transaction Lines'), ...)
: This scans the entire table (12 million rows) for each evaluation, which is computationally intensive.SUMX
over SUMMARIZE
with nested calculations adds to the processing time.We can optimize the measure by:
CALCULATE
instead of FILTER(ALL(...))
.Here's the optimized measure:
Job Cost =
VAR PoNumber =
RIGHT( MAX( 'Transaction Lines'[Logistics Kitting Job Costing PO#] ), 18 )
VAR ItemID =
MAX( 'Transaction Lines'[Item Internal ID] )
RETURN
IF(
NOT ISBLANK( PoNumber ),
CALCULATE(
SUM( 'Transaction Lines'[Amount] ),
'Transaction Lines'[Document Number] = PoNumber,
'Transaction Lines'[Item Internal ID] = ItemID
),
BLANK()
)
Data Types Consistency:
Document Number
, Logistics Kitting Job Costing PO#
, and Item Internal ID
are consistent (e.g., all text or all numbers). Mismatched data types can cause performance issues.VALUE
or FORMAT
.Avoid Using RIGHT
in Filters if Possible:
RIGHT
.Test Performance:
Consider Using KEEPFILTERS
:
KEEPFILTERS
to ensure they behave as intended.Job Cost =
VAR PoNumber =
RIGHT( MAX( 'Transaction Lines'[Logistics Kitting Job Costing PO#] ), 18 )
VAR ItemID =
MAX( 'Transaction Lines'[Item Internal ID] )
RETURN
IF(
NOT ISBLANK( PoNumber ),
CALCULATE(
SUM( 'Transaction Lines'[Amount] ),
KEEPFILTERS( 'Transaction Lines'[Document Number] = PoNumber ),
KEEPFILTERS( 'Transaction Lines'[Item Internal ID] = ItemID )
),
BLANK()
)
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn|Twitter|Blog |YouTube
I still haven't solved this, but I needed to park it for now and move onto another project.
Hi Vahid, thanks for your quick and detailed response. This has saved the time, which is now 12 seconds down from 24. The only issue is that the totals aren't correct. JobCost 2 is a new formula, but the total isn't right, showing 1,700 instead of 7,300. Any ideas?
Hi @Steve_M ,
It's been a while since I heard back from you and I wanted to follow up. Have you had a chance to try the solutions that have been offered? If the issue has been resolved, can you mark the post as resolved? If you're still experiencing challenges, please feel free to let us know and we'll be happy to continue to help!
Looking forward to your reply!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
9 | |
8 | |
8 | |
7 |
User | Count |
---|---|
14 | |
12 | |
11 | |
10 | |
9 |