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
lekkerbek
Helper IV
Helper IV

Mapping different depending on total sum

Hi,

I created a model to show a balance sheet. This model has a couple of tables:

 

DimGLaccounts -> GL number, GL description, BalanceType

DimGLMapping -> GL number, Mapping code

DimGLClassificationRelations -> the build up of the balance sheet

Transactions -> date, GL number, Amount, etc

 

In some cases GL accounts could be on the debit side of the balance sheet, but if the amount is negative it should be on the credit side of the balance sheet.

 

For example I have GL accountnumber 06520 which is a current account with a group company.

 

If the amount is positive it should be mapped to "receivables from group companies" which is:

E-B1010203

 

If the amount is negative it should be mapped to "payable to group companies" which is:

E-B10204

 

Is this somehow possible within Power BI? The problem is that is to calculate a total sum of a specific GL account from another table and then determine if it should be either this mapping or the other. This mapping could me different for multiple GL Accounts.

6 REPLIES 6
lekkerbek
Helper IV
Helper IV

@DataInsights 

 

GL Mapping = 
VAR vDebitMapCode =
    MAX ( DimGLClassificationMappings[Debet mapping] )
VAR vCreditMapCode =
    MAX ( DimGLClassificationMappings[Credit mapping] )
VAR vDebitMapping =
    CALCULATE (
        MAX ( DimGLClassificationReturns[Fin Stmt Line] ),
        DimGLAccountClassificationRelations[CODE_ATTR] = vDebitMapCode
    )
VAR vCreditMapping =
    CALCULATE (
        MAX ( DimGLClassificationReturns[Fin Stmt Line] ),
        DimGLAccountClassificationRelations[CODE_ATTR] = vCreditMapCode,
        USERELATIONSHIP ( DimGLAccountClassificationRelations[CODE_ATTR], DimGLClassificationMappings[Credit mapping] )
    )
VAR vResult =
    IF ( [Total Amount] > 0, vDebitMapping, vCreditMapping )
RETURN
    vResult

 

 

 

 

I'm not sure:

* what to put here: "DimGLClassificationReturns[Fin Stmt Line]" as my model is different and not sure what it does.

 

* how to build up the visual to leave the current setup in tact, but it just switches the mapping to the other side if needed.

@lekkerbek,

 

Try these measures. Delete the relationships between DimGLClassificationMappings and DimGLAccountClassificationRelations

 

Total Amount = SUM ( Transactions[Amount] )

Dynamic Amount = 
VAR vMapping =
    MAX ( DimGLAccountClassificationRelations[CODE_ATTR] )
VAR vAccountBalance =
    ADDCOLUMNS (
        SUMMARIZE (
            DimGLClassificationMappings,
            DimGLClassificationMappings[GL Account],
            DimGLClassificationMappings[Debit Mapping],
            DimGLClassificationMappings[Credit Mapping]
        ),
        "tmpTotalAmount", [Total Amount]
    )
VAR vAccountMapping =
    ADDCOLUMNS (
        vAccountBalance,
        "tmpMappingToUse",
            IF (
                [tmpTotalAmount] > 0,
                DimGLClassificationMappings[Debit Mapping],
                DimGLClassificationMappings[Credit Mapping]
            )
    )
VAR vAccountToSum =
    FILTER ( vAccountMapping, [tmpMappingToUse] = vMapping )
VAR vResult =
    SUMX ( vAccountToSum, [tmpTotalAmount] )
RETURN
    vResult

 

Create visual using DimGLAccountClassificationRelations[DESCRIPTION] (and additional columns from this table).

 

DataInsights_0-1605220121242.png

 

DataInsights_1-1605220138576.png

 





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

Proud to be a Super User!




Thank you @DataInsights. It's not exactly working the way I want it to be, but that has to do with my model I guess. I'm going to study this. Thanks for leading me in the right direction.

DataInsights
Super User
Super User

@lekkerbek,

 

This approach uses two mapping code columns in DimGLMapping:

 

DataInsights_0-1605128787493.png

 

Data model:

 

DataInsights_3-1605129432237.png

The inactive relationship is between DimGLMapping[Credit Mapping Code] and DimGLClassificationReturns[Mapping Code].

 

Measures:

 

Total Amount = SUM ( Transactions[Amount] )

GL Mapping = 
VAR vDebitMapCode =
    MAX ( DimGLMapping[Debit Mapping Code] )
VAR vCreditMapCode =
    MAX ( DimGLMapping[Credit Mapping Code] )
VAR vDebitMapping =
    CALCULATE (
        MAX ( DimGLClassificationReturns[Fin Stmt Line] ),
        DimGLClassificationReturns[Mapping Code] = vDebitMapCode
    )
VAR vCreditMapping =
    CALCULATE (
        MAX ( DimGLClassificationReturns[Fin Stmt Line] ),
        DimGLClassificationReturns[Mapping Code] = vCreditMapCode,
        USERELATIONSHIP ( DimGLClassificationReturns[Mapping Code], DimGLMapping[Credit Mapping Code] )
    )
VAR vResult =
    IF ( [Total Amount] > 0, vDebitMapping, vCreditMapping )
RETURN
    vResult

 

Note the difference in GL Mapping when the amount is positive vs. negative:

 

DataInsights_1-1605128826767.png

 

DataInsights_2-1605128838146.png

 

Let me know if this works in your data model. If not, please post a pic of your data model, desired result, and sample data (in a format that can be copied into Power BI).





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

Proud to be a Super User!




@DataInsights


Thank you so far for your help. I have implemented the debit and credit mapping, but I'm having trouble with implementing the measure. Please find attached screenshots of:

1) my model

2) partial details of my relations table

3) how my balance sheet matrix is setup

 

1. Model.PNG2. DimGLAccountClassificationRelations.PNG3. Visual.PNG

@lekkerbek,

 

Would you post your measure so I can review the DAX? Are you getting an error, or the wrong result?





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

Proud to be a Super User!




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.