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
croberts21
Responsive Resident
Responsive Resident

How to sum a cost based on field in another related table.

I have PBI Desktop from March 2023. I am trying to sum costs with a wipcategoryid of "10" or "50". Wipcategoryid looks like a number but is a string.

I have these tables with these fields:

Table: Jobcost
jobid (the job number)
actcode (activity code)
actcost (actual cost, this is sometimes null)

 

Table: ActivityCode
ActivityCode (connects to Jobcost.actcode)
Wipcategoryid (what I need to filter on)

 

There are other tables that connect to Jobcost. 

 

The relationship between Jobcost.actcode and ActivityCode.Activitycode is many to many for some reason.

 

Columns in my report table viz: jobid, Postage (a measure or column)

 

What I need: For each jobid in the table viz, sum all Jobcost.actcost records where ActivityCode.WipcategoryID="10" or "50".

 

I have tried to copy the Wipcategoryid to my Jobcost table with this column: `WipCatId = RELATED(Activitycode[jcwipcatid])` but I got an error "The column 'ActivityCode[jcwipcatid]' either doesn't exist or doesn't have a relationship to any table available...'. When in my relationships I link Jobcost.actcode to ActivityCode.Activitycode. But RELATED() cannot be used in a many-to-many relationship, which I have. See https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-relationships-understand#limited-...

 

I have tried these as columns and measures added to the Jobcost table and none have worked:

 

Measure: PostFrtMeas = CALCULATE(SUM('Jobcost'[jcactcost]), OR(RELATED(Activitycode[jcwipcatid])="10", RELATED(ActivityCode[jcwipcatid])="50"))) The error I get is "Column 'jcactcost' in table 'Jobcost' cannot be found or may not be used in this expression."

 

Column: PostFrtCol = CALCULATE(SUM('Jobcost'[jcactcost]), OR(Activitycode[jcwipcatid]="10",ActivityCode[jcwipcatid]="50"))
The error I get for this is The error I get is "Column 'jcactcost' in table 'Jobcost' cannot be found or may not be used in this expression."

 

Any ideas how to get this to work? I can't seem to find any formulas in tutorials that make filter criteria based on a connected but different table. And the Microsoft documentation does not say whether or not other tables can be used in various expressions or formulas.

Thank you!

 

Update: Ok I have fixed this. I changed the source SQL to link the 2 tables Jobcost.actcode with Activitycode.Activitycode. I also had renamed Jobcost.jcactcost to actcost so that part is also fixed.

 

Please consider this closed.

0 REPLIES 0

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.