Forum Discussion

BI_kartik's avatar
BI_kartik
Frequent Visitor
3 years ago

USERELATIONSHIP complex case

Hi, 
I have a following business problem that I need your help solving.
I have two Dimension tables - Account Type DIM and Volume Type DIM
and One FACT table - Volume FACT (This is just a part of my complex data model)
The relationships from DIM to FACT are one to many and all are inactive relationships (I know I can keep one active relationship but I have delibrately kept it inactive). I have marked all the relationships columns in the below screen shot. 

 



I want to calculate Total volume which can be done by summing the following columns =
VOLUME FACT[manual_opened_usd_volume] + VOLUME FACT[manual_closed_usd_volume] + VOLUME FACT[copytrading_opened_usd_volume] + VOLUME FACT[copytrading_closed_usd_volume]

Now In the report view I have the following slicers


I want the Total Volume to change when I interact with the slicers.
Let me share the DAX Expression that I wrote.

Total Volume_new =
VAR __Manual_open_volume =
CALCULATE(
    CALCULATE(
        SUM(
            'VOLUME FACT'[manual_opened_usd_volume]
        ),
        USERELATIONSHIP(
            'VOLUME FACT'[Manual Open Volume Index],
            'Volume Type DIM'[Index]
        )
    ),
    USERELATIONSHIP(
        'VOLUME FACT'[Provider Index],
        'Account Type DIM'[id]
    ),
    USERELATIONSHIP(
        'VOLUME FACT'[Follower Index],
        'Account Type DIM'[id]
    )
)

VAR __Manual_close_volume =
CALCULATE(
    CALCULATE(
        SUM(
            'VOLUME FACT'[manual_closed_usd_volume]
        ),
        USERELATIONSHIP(
            'VOLUME FACT'[Manual Close Volume Index],
            'Volume Type DIM'[Index]
        )
    ),
    USERELATIONSHIP(
        'VOLUME FACT'[Provider Index],
        'Account Type DIM'[id]
    ),
    USERELATIONSHIP(
        'VOLUME FACT'[Follower Index],
        'Account Type DIM'[id]
    )
)

VAR __Copytrading_open_volume =
CALCULATE(
    CALCULATE(
        SUM(
            'VOLUME FACT'[copytrading_opened_usd_volume]
        ),
        USERELATIONSHIP(
            'VOLUME FACT'[Copy Trading Open Volume Index],
            'Volume Type DIM'[Index]
        )
    ),
    USERELATIONSHIP(
        'VOLUME FACT'[Provider Index],
        'Account Type DIM'[id]
    ),
    USERELATIONSHIP(
        'VOLUME FACT'[Follower Index],
        'Account Type DIM'[id]
    )
)

VAR __Copytrading_close_volume =
CALCULATE(
    CALCULATE(
        SUM(
            'VOLUME FACT'[copytrading_closed_usd_volume]
        ),
        USERELATIONSHIP(
            'VOLUME FACT'[Copytrading Close Volume Index],
            'Volume Type DIM'[Index]
        )
    ),
    USERELATIONSHIP(
        'VOLUME FACT'[Provider Index],
        'Account Type DIM'[id]
    ),
    USERELATIONSHIP(
        'VOLUME FACT'[Follower Index],
        'Account Type DIM'[id]
    )
)

RETURN

__Manual_open_volume
+
__Manual_close_volume
+
__Copytrading_open_volume
+
__Copytrading_close_volume

The Result is not filtering the data as it should and giving the following error when i select provider / follower from account_type slicer

 

 

 

4 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi BI_kartik 
    Please try

    Total Volume_new =
    SUMX (
        VALUES ( 'Account Type DIM'[id] ),
        VAR CurrentAccount = 'Account Type DIM'[id]
        RETURN
            CALCULATE (
                VAR __Manual_open_volume =
                    CALCULATE (
                        SUM ( 'VOLUME FACT'[manual_opened_usd_volume] ),
                        USERELATIONSHIP ( 'VOLUME FACT'[Manual Open Volume Index], 'Volume Type DIM'[Index] )
                    )
                VAR __Manual_close_volume =
                    CALCULATE (
                        SUM ( 'VOLUME FACT'[manual_closed_usd_volume] ),
                        USERELATIONSHIP ( 'VOLUME FACT'[Manual Close Volume Index], 'Volume Type DIM'[Index] )
                    )
                VAR __Copytrading_open_volume =
                    CALCULATE (
                        SUM ( 'VOLUME FACT'[copytrading_opened_usd_volume] ),
                        USERELATIONSHIP ( 'VOLUME FACT'[Copy Trading Open Volume Index], 'Volume Type DIM'[Index] )
                    )
                VAR __Copytrading_close_volume =
                    CALCULATE (
                        SUM ( 'VOLUME FACT'[copytrading_closed_usd_volume] ),
                        USERELATIONSHIP ( 'VOLUME FACT'[Copytrading Close Volume Index], 'Volume Type DIM'[Index] )
                    )
                RETURN
                    __Manual_open_volume + __Manual_close_volume + __Copytrading_open_volume + __Copytrading_close_volume,
                'VOLUME FACT'[Provider Index] = CurrentAccount,
                'VOLUME FACT'[Follower Index] = CurrentAccount
            )
    )
    • BI_kartik's avatar
      BI_kartik
      Frequent Visitor

      Thank you for your response tamerj1
      But your solution is not working. Im getting blank if I select between provider and follower. Also, with no filter applied, the total volume is not correct.

      • tamerj1's avatar
        tamerj1
        Community Champion

        BI_kartik 
        This is the logic that I understood from your DAX code. I believe this is the condition that generates blanks everywhere

                    'VOLUME FACT'[Provider Index] = CurrentAccount,
                    'VOLUME FACT'[Follower Index] = CurrentAccount

        What did you mean by activating the two relationships between 'VOLUMN FACT' and 'Account Type DIM' together?