Skip and use relationship in one measure

Hi! :slight_smile: I’ve got a problem once again, this time I think it’s a huge one.

I’ve got the fact table, image below. UNIODDZIAL_ID is branch ID from dimension table about contract ID, KSOBROTY_ZLEC is contract ID, KSOBROTY_WN is cost.

Contract ID has a relationship with dimension table, which contains info about which branch has that contrant.

Here is the case. There are situation, that some branch is working on a contract for another branch. This information is in KSOOBROTY_KONTO (There is info about which branch make that cost, some some accounting informatios and info about contract id and its owner. It’s basicly account description). I want to show total costs assing to branches from contract id, so it’s not a problem, beacuse with my relation I can assign costs to the appropriate branches under the contract. But in one case i have to do it another way.

For one branch (Call it Branc X) I’ve to sum it’s cost by information from KSOOBROTY_KONTO which is incompatible with branch coming from contract id. I must have info about all costs of that branch, does not matter if it is that branchs contract or not. So what i want powerbi to do?

Something like:

  1. Sum column KSOOBROTY_WN by branch number from KSOOBROTY_KONTO, but only for one specific branch (Sum cost by information who make that cost, skip info about which contract is it).
  2. In other situation use realtion and sum values by contract id but skip those costs that were included in previous counting, do not duplicate them. (Sum cost by information whose contract is it.)

I could make 2 measures, but I have to show both values in one table so it has to be one measure.

When i delete relationship and use Branch ID from info about who made that cost, I’ve got good result for Branch X, but when I make the relationship, I’ve got good resuls for all branches but not for Branch X.

For me it’s a huge problem, I feel like my brain is going to explode :slight_smile: :scream: Please help me!

@wojteq,

Well, let’s see what we can do to keep your brain from exploding… :grinning:

Unfortunately, this problem is too complex (for me at least) to solve just based on the information above. I will really need to see your PBIX file, as well as a mockup of the results you would like to achieve.

Here’s a video with some simple techniques for anonymizing/masking sensitive information in your dataset so that you can post it on the forum for us to work with:

Once we have that, I’m confident we can work through a solution with you.

Thanks.

  • Brian
2 Likes

Hi! :slight_smile:

Here is my data model, of course I change all names and there is only necessary data.
pbix test data.pbix (1.2 MB)

Let’s work on August as an example.

I want to have these results:

  • od5 - 1 130 381
  • od8 - 1 695 035
  • od13 - 2 172 142
  • od10 - 1 688 442
  • od11 - 467 368

And here are the conditions:

  • for od11 I have to count total costs by “BRANCH_NAME_WHO_WORK”;
  • for other 4 branches (od5, od8, od13, od10) I have to count total costs by branch coming from contract, so by branch from table “Contracts” and column “CONTRACT_BRANCH”;
  • for this 4 branches I have to count only costs that have “CONTRACT_ID” like “KK%”, “KD%”, “KP%”; for od11 all contracts, whatever its name is, that is why i create column “COSTS 3”
  • and of course finally I want to show this results in one table, using “BRANCH_NAME” from table “Branch”

My totals are identical to those I want to get, but like I said, with active relationship I’ve got good result for 4 branches, when relationship is not active and I’m counting by “BRANCH_NAME_WHO_WORK” result is good only for od11.

Sory, one mistake :slight_smile: When I’m counting using relatioship, my total for od10 is 1 946 695. It should be 1 688 442 like I write before. It is beacuse values 254 396 and 3 857 should be shown in od11 branch :slight_smile:
image

So, these are results using relationship and correct results next to them:
image

And here are result using “BRANCH_NAME_WHO_WORK”:
image

Of course I’m trying to solve this problem on my own, but I really count on your help! Thanks in advance for help!

EDIT/
I make second relationship to table Branch, and use function USERELATIONSHIP and I’ve got perfect results for od11, but those contracts which are in od11 are duplicated in od10 and there are contracts which are not starting like KK, KD or KP in od10, even though I made column COSTS3. Here is current file.
pbix test data.pbix (1.2 MB)

@wojteq,

Thanks very much for the file and the detailed explanation – that will definitely help me develop a good specific solution for you. One more request though - I can tell I’m going to need to do some Power Query transformations, so can you please also send me the two Excel files (data.xlsx and contracts.xlsx)?

Thanks.

– Brian

Can you give me your email address? Files are to big to send them here.

So @BrianJ, I think the only case to solve now are duplicated values in other branches. If values that are in os11 would not be in other branches the results would be perfect.

EDIT/
In my original file I made some changes. Now really the only case to solve is how to eliminate from 4 branches those contracts which are shown in os11. Because there are those, like KK200073. Maybe I’ll put those changes to file that I send here? Although I think it is not neccessary,

@wojteq,

If you could please send along the most recent version of the file, that would be great – just to make sure we are working off the same data and model.

Thanks.

  • Brian

Of course :slight_smile:
pbix test data.pbix (1.0 MB)

Here are my actual results and next to them correct one:
image

Those contracts which are in od11, should not appear in od10 or any other branches (in this example this situation is in od10 only).

Edit/
Oh and there is a problem that total does not include od11 result :confused: I know that this happend because of my measure but I can’t solve it. Summarize dose not work here :confused:

@wojteq,

Before going to work on your DAX, we need to address issues in your data model. The structure below is very problematic because once the relationship between the branch table and the fact table is activated, it creates an ambiguous path between the two tables, where the fact table can now be reached via path #1 or path #2. This can wreak havoc with your DAX resulting in incorrect results.

However, the model is easily revisable to conform to a standard star schema by reconfiguring it in the following way:

Below are the results with the revised data model. Please take a look and see if this is producing accurate results. (I wasn’t able to validate outside of PBI, since I don’t have share rights to the Google Drive link to your fact table that you sent me yesterday.).

Thanks.

  • Brian

image

1 Like

Thanks for the answer @BrianJ. Now you have an access to my files.

Unfortunately the results are wrong. Those which I write in the previous post are almost correct. The correct ones are with blue line.
image

So with no relationship between Contracts and Branch we can’t have correct results in my opinion. Contracts table is there to tell us which branch has a specific contract assigned, so in my opinion I have to tell PBI that those branches in table Contracts are branches from table Branch.

Oh, I just find out, that there are actually no contracts that are duplicated, but that situation could happen so it would be nice to have a solution.
The only issue that is in my results is that contract KK200073 should be assign to od11 instead of od10. But! That information does not come either from Contracts table or column “BRANCH_NAME_WHO_WORK”. This is a Business requirement and it is simply meant to be like this.

@wojteq,

I’m going to have to dig into this with fresh eyes tomorrow, since I can’t see how for od5, od8 and od13 your results with filters are larger than my results using your Total Cost 2 measure, which is just a straight up SUM with no filters.

– Brian

image

@BrianJ but I’m using measure “Total Costs 2 w/FILTER” beacuse those filters have a huge impact on result. Check what result you have with that measure.

@wojteq,

Let’s work first on validating the Total Cost 2 measure that forms the foundation of the other filtered measure.

Here’s what I did to validate my results from Total Cost 2:

Note: For all below, ACCOUNT_NR 550 and 590 are filtered out (per your page filter). I’ve also calculated the totals over all months now, just for simplicity’s sake.

The first uses the branch name from the branch table of my revised data model and your Total Costs 2 measure
The second uses the same branch name field, but a revised measure that is just the simple SUM( FactCost(Cost])
The third is totally done in PQ and completely independent of data model. I merged the branch name field onto a copy of the fact table, filtered the records for Acct NR 500 and 590, grouped on branch name and used the SUM function on the new column created:

As you can see, all three approaches check out to the penny. Let’s make sure you are getting the same results from your analysis, and then we can take the same approach to validating the filtered Total Cost 2 w/ Filters measure.

Sound reasonable?

  • Brian

Ok, so when I delete relationship between Branch and Contract tables I’ve got the same results as you while using “Total Cost 2”.

image

Then, when I use “Total Costs 2 w/FILTERS” but also with deleted relationship I’ve got these results:
image

And finally, when I turn on relationship and use “Total Costs 2 w/FILTERS” I’ve got these results:
image

But I would like us to work on August, because I don’t have good informations about results for 1-6 months, I’ve got only 7-8 months results.

@wojteq,

OK, good - we’re making progress. I am heading into a training course until mid-evening tonight, but will work on the PQ validation of the Total Costs 2 w/ filters measure tonight, so we’ll know exactly what the correct target for our DAX measure(s) will be. From there, getting the rest of it sorted out should be pretty straightforward.

  • Brian
1 Like

@wojteq,

Just wanted to let you know that I haven’t at all forgotten about you. I’ve been working on this one nightly, but it’s proving more difficult to crack than I expected. Will keep at it and keep you posted. Sorry for the delay…

  • Brian
1 Like

No problem @BrianJ. I tried to use some solutions but they don’t work. And of course one more problem is that my total result does not include od11.

image

Total result here should be 7 157 225 (skipping that issue with duplicated contracts).

Hi @BrianJ, did you come up with a solution to the problems? I still can not solve problem of duplicated contracts and wrong total result :confused:

@wojteq,

I’m caught in the weeds on this one - not getting it to work properly. Going to get some other eyes from the expert team on it…

  • Brian

Thanks.

@Melissa maybe you have some time to look at this problem? :slight_smile: I mark you because so far I don’t know more experts than you and @BrianJ :slight_smile: