Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Complex calc of values in a difficult data model with hieracies and complex relations. HELP me!

Dear all, 😓

I'm struggling since many days to solve a problem but evidently I am not able to do it.

I have a complex data model in which it all starts from Riclassified Budget Schemas.
You can download the example pbix file from here.
From this schemas, I go through a table called "SchemaConstructor" where I made the levels of hieracy.
Then, from "SchemaConstructor" I go through "SchemaBalancesLink" to a table (BALANCES) where I have many Values associated to many "CostItems". Then I have many measures who let me also select which kind of values I can include or exclude in the "STD Amount."

At this point, evenything's fine:
If you try to select a line (Group) from the central table (Riclassified Budget Schema), You will see which are the detailed CostItems and CostCenter that composes the Group with the correct Value.
For any CostItem, we can have many CostCenter, so we can find a specific summed value, retrieved and calculated from "BALANCES" and I have all the measures to do this, for all the lines made up by the association of CostItem+CostCenter.

Then here you are what I cannot do:
There is another table called REALLOCATIONS that I need to use.
Every record of Reallocations tells me an AMOUNT that is moved from an Original CostCenter (relatively to a specific CostItem)  to Destination CostCenter.

What I need is to have a selector that allow me to choose if I wanna see the STD amount (calculated from Balances) and the relative list of CostItems+CostCenters.... or if I wanna see an amount calculate from what I retrieve in Balances but updated by what I find in Reallocations.

It's very difficult also to explain. 😅 Hope someone will try to help me.
I'm here to help anyone who will try to do it.
You can also contact my on skype "giovannibracci". (I'm in Italy)

Thank you thank you thank you to those who will try to help me 🙏

2 ACCEPTED SOLUTIONS
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Sorry for replying late.

I make a test based on a simple data->BALANCES[CGDataCompetenzaAvere].

Change the relationships as below:

Then create measures and add some measures into the visual level filter

Measure = CALCULATE ( SUM ( BALANCES[CGDataCompetenzaAvere] ), USERELATIONSHIP ( BALANCES[CostCenter], CostCenterDatabase[CostCenter] ) ) + 0 

Measure 2 = CALCULATE ( SUM ( REALLOCATIONS[Amount] ), USERELATIONSHIP ( REALLOCATIONS[DestinationCostCenter], CostCenterDatabase[CostCenter] ) ) 

Measure 3 = [Measure]-[Measure 2] 

Measure 4 = CALCULATE ( MAX ( REALLOCATIONS[DestinationCostCenter] ), USERELATIONSHIP ( REALLOCATIONS[DestinationCostCenter], CostCenterDatabase[CostCenter] ) ) 

Measure5 = IF([Measure 3]<>0,[Measure 3]) 

 

Best Regards
Maggie
Community Support Team _ Maggie Li
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

Hi @Anonymous 

Capture15.JPGCapture16.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
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

9 REPLIES 9
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Sorry for replying late.

I make a test based on a simple data->BALANCES[CGDataCompetenzaAvere].

Change the relationships as below:

Then create measures and add some measures into the visual level filter

Measure = CALCULATE ( SUM ( BALANCES[CGDataCompetenzaAvere] ), USERELATIONSHIP ( BALANCES[CostCenter], CostCenterDatabase[CostCenter] ) ) + 0 

Measure 2 = CALCULATE ( SUM ( REALLOCATIONS[Amount] ), USERELATIONSHIP ( REALLOCATIONS[DestinationCostCenter], CostCenterDatabase[CostCenter] ) ) 

Measure 3 = [Measure]-[Measure 2] 

Measure 4 = CALCULATE ( MAX ( REALLOCATIONS[DestinationCostCenter] ), USERELATIONSHIP ( REALLOCATIONS[DestinationCostCenter], CostCenterDatabase[CostCenter] ) ) 

Measure5 = IF([Measure 3]<>0,[Measure 3]) 

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi Maggie @v-juanli-msft ,

 

this solution seems to perfectly fits what I need.

GREAT! I've never thought about defining which relations to use just into any single measure, without activate it in the whole data model.

I've applied your suggestions and measures to my original data model and it works.

Now I'll practice a bit just to undestand how I could manage filters and relations, but thanks to your help I've made a big big step forward.

 

Thank you.

 

v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

The pbix is large and the progress hangs on.

Before i can look clearly into you pbix, please consider the idea below:

What relationship among "REALLOCATIONS" and other tables based on bussiness analysis?

"if I wanna see an amount calculate from what I retrieve in Balances but updated by what I find in Reallocations", for this , actually, i don't know what is the "what"?

 

Best Regards

Maggie

Anonymous
Not applicable

Hi Maggie @v-juanli-msft ,

I'll try to go deeper into the relations between tables in the data model.

 

- SCHEMAS (Contains the Riclassified Budgets that one can choose):
We can start from the table called "SCHEMAS" that is simply a list of Riclassified Budget schemes that one can choose from.
The selected scheme is the one I can see represented in the bigger visual on the first page of the report.

 

- SchemaConstructor (Contains the structures of the Riclassified Budgets):
By the field "Schema", the SCHEMAS table filters the SchemaConstructor table.
For each "Schema", SchemaConstructor table purpose is to define the structure of the selected Riclassified Budget based on a "Group" and " TotalizeIntoGroup" hieracy, as you can see in the "Path" and "Level #" fields. Each "Group" corresponds to a line of the bigger visual representing the selected Riclassified Budget.
This table contains a field called "KeyGroupType" that results from the concatenation of "Schema" & "Group" fileds.

 

- SchemaBalancesLink (contains the reference to "CostItem"):
"KeyGroupType" is the link between SchemaConstructor and SchemaBalancesLink tables.
SchemaBalancesLink shows which is the "CostItem" related to each "Schema"&"Group" key.
This link is what I need to retrieve the values related to that CostItem in the BALANCES table.
Let's see BALANCES.

 

- BALANCES (contains the values):
SchemaBalancesLink is linked to BALANCES table by "CostItem" field.
Each record of BALANCES contains a set of values for a specific "Year" & "Month" period and also a specific "CostCenter".
Indeed, a "CostItem" can be itemized into many "CostCenter" so that in BALANCES there can be many records related to the same "CostItem" and same "Year" & "Month" period but with different Cost Centers.
Indeed, when you select a specific "Group" of the selected Riclassified Budget into the main visual of the report, the 2 visual below would list the Cost Items but also the Cost Centers linked to that "Group". The different kind of amounts are all summed up by specific measures, thanks to the hieracy defined in the SchemaConstructor table.
In BALANCES we have a field that is Key to reach REALLOCATIONS table, formed by the concatenation of "Year", "Month", "CostItem" & "CostCenter".

 

- REALLOCATIONS:
Each record in the table contains the specific amount for a particular combination of period ("Year" & "Month"), "CostItem" and "CostCenter".
However, there are 2 fields about Cost Center. One for the Cost Center of ORIGIN and one from the Cost Center of DESTINATION.
This means that I can have a useful record to move the specified amout from a CostCenter of Origin (the one coming from BALANCES), to a Cost Center of Destination (defined in REALLOCATIONS).

 

E.G.
Lets say we have 1 record in BALANCES:

CostItem

CostCenter

Year

Month

Value

003104000010

CR-0155

2019

1

85,0

 

 

 

 

 

 

 

 

 

85,0

And 3 records in REALLOCATIONS:

CostItem

CostCenter ORIGIN

CostCenter DESTINAT.

Year

Month

Value

003104000010

CR-0155

CR-0155

2019

1

85,0 (subtract from balances)

003104000010

CR-0155

CM-7060

2019

1

-80,0 (add to balances)

003104000010

CR-0155

CM-7064

2019

1

-5,0 (add to balances)

 

 

 

 

 

00,0

 

This situation means that if I choose to include the reallocations, the amount calculated earlier and based only on BALANCES table should be affected by the changes of REALLOCATIONS table.


Looking at the example, as a result of considering REALLOCATIONS:

  • I should not find in the details of main visual – actually no more – the CR-0155 cost center, because its entire amount of 85 is inside the first record in REALLOCATIONS with the same origin & destination (attention… don’t let you be confused by the operator! You will find the inverted mathematical operator. Actually you should consider postitive amounts in Riallocations as to subtract from BALANCES and negative amounts in REALLOCATIONS as to add to BALANCES). This means that CostCenter CR-0155 resulting from BALANCES has been totally emptied and that the amount is converged into CM-7060 and CM-7064.
  • This also mean that CR-0155 should disappear from the smaller visual with the CostCenter details and in its place should come up CM-7060 (80,00) and CM-7064 (5,00).

 

Hope to have been clear. 🤔

Let me know if it helps.

Thank you! 🙏

Hi @Anonymous 

Please check if my undertsanding is correct.

 

"What I need is to have a selector that allow me to choose if I wanna see the STD amount (calculated from Balances) and the relative list of CostItems+CostCenters.... or if I wanna see an amount calculate from what I retrieve in Balances but updated by what I find in Reallocations."

 

1.the STD amount (calculated from Balances) and the relative list of CostItems+CostCenters

=> this is the result of your [STD Amount],

2.an amount calculate from what I retrieve in Balances but updated by what I find in Reallocations

=>this is what you need (i call it expected result)

3.The rule to calculate the expected result

=> you use the CostItem=003104000010 to give an example, the expected result should be 0, in your pbix, we should calcualte it based on your [STD Amount].

 

Best Regards

Maggie

 

 

 

Anonymous
Not applicable

@v-juanli-msft 

 

Dear Maggie,

 

I am going to reply point by point.

 

1.the STD amount (calculated from Balances) and the relative list of CostItems+CostCenters

=> this is the result of your [STD Amount],

 

Exactly, it is. Let's make an example!

Firts of all, let's put some filters to simplfy:

  • CostItem = 003104000010;
  • Year = 2019;
  • Month = 1

01.jpg

We have a calculate STD Amount of 2.867,80, related to CostItem 003104000010 and to many CostCenters as you can see above in the image. One of this CostCenter, for example, is CR-0155 that takes part for 85,00.
(Let's also notice that  CM-1020 has STD Amount = 79,00 and that CM-1010 is not even in the list. This will be helpful while proceeding with the example.

 

Indeed, if we look inside BALANCES table applying the same filters, we'll notice many records related to many "CostItem&CostCenter" keys and the SUM of the amount in the values column will be 2.867,80 (only from BALANCES).

Only one record is related to the CostCenter CR-0155, for an amount of 85,00.
02.jpg

 

2. an amount calculate from what I retrieve in Balances but updated by what I find in Reallocations

=>this is what you need (i call it expected result)

3.The rule to calculate the expected result

=> you use the CostItem=003104000010 to give an example, the expected result should be 0, in your pbix, we should calcualte it based on your [STD Amount].

 

Yes, the expected result at point 2 should be an amount calculated from what I retrieve in Balances modified by what I find in Reallocations. I will try to explain better the logic rule that should be used to build the right measure, for your point 3:


Let's look inside REALLOCATIONS, filtering the same period, same CostItem and OriginalCostCenter = CR-0155.

In the last line (blue point) of the image below you will see OriginalCostCenter CR-0155 & DestinationCostCenter CR-0155 for 85,00. This means that the amount found in BALANCES related to the filtered period, filtered CostItem, for CostCenter CR-0155,  should be totally emptied for 85,00.

03-1.jpg
The other records represents the DestinationCostCenter to which the OriginCostCenter transfers its amount's portions.
You can also see that part of the amount goes to CM-1020 for 0,95 and to CM-1010 for 1,8.
Let's ignore the other records and imagine the presence of only CM-1020 & CM-1010 in the DestinationCostCenter.

 

The expected result should be this:

04.jpg

 

Hope it helps. Thank a lot Maggie!

Hi @Anonymous 

Capture15.JPGCapture16.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @Anonymous 

It is appreciated of you to share so detailed information.

 

Best Regards

Maggie

Anonymous
Not applicable

@v-juanli-msft 
Maggie, it's the least I can do to try to put someone in a position to help me.

And I really need someone who will! 😄

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.