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
Anonymous
Not applicable

Substract value based on 2 filters on the same dimension

Dear all,'

 

I have an issue trying to calculate the difference between 2 entities using 2 slicers.

 

database: table with 4 entities with associated amounts.

d_entity: table with entity description and hierarchy

d_entity_bis: reference of d_entity

 

I have 1 slicer based on d_entity and another based on d_entity_bis and I would like to substract the amount of entities selected with the first slicer by the amount of entities selected with the second slicer.

 

I tried this measure, but it did not work:

Diff = 
CALCULATE ( SUM ( Database[Amount] ); ALLSELECTED ( d_entity[entity_code] ) ) - 
CALCULATE ( SUM (  Database[Amount] ); ALLSELECTED ( d_entity_bis[entity_code] ) )

 

Any ideas ?

 

Here below the screenshot of my test case:Capture.PNG

 

 

 

1 ACCEPTED SOLUTION

HI @Anonymous ,

In your scenario, we need to remove the relationship between these tables, then use the following DAx query:

Diff =
CALCULATE (
    SUM ( Database[Amount] ),
    FILTER (
        ALL ( Database ),
        Database[Entity_code] IN ALLSELECTED ( d_entity[entity_code] )
    )
)
    - CALCULATE (
        SUM ( Database[Amount] ),
        FILTER (
            ALL ( Database ),
            Database[Entity_code] IN ALLSELECTED ( d_entity_bis[entity_code] )
        )
    )

The result will like below: 

PBIDesktop_5ZZZAuAoMJ.png

By the way, the custom visual hierarchy slicer has some problem, when I select the A and B, it will display the true data, but when I select the Grp_1, it will not display the true data.

Best Regards,

Teige

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Need help !

Here is the PBIX if needed.

 

Best regards

Emilien

HI @Anonymous ,

In your scenario, we need to remove the relationship between these tables, then use the following DAx query:

Diff =
CALCULATE (
    SUM ( Database[Amount] ),
    FILTER (
        ALL ( Database ),
        Database[Entity_code] IN ALLSELECTED ( d_entity[entity_code] )
    )
)
    - CALCULATE (
        SUM ( Database[Amount] ),
        FILTER (
            ALL ( Database ),
            Database[Entity_code] IN ALLSELECTED ( d_entity_bis[entity_code] )
        )
    )

The result will like below: 

PBIDesktop_5ZZZAuAoMJ.png

By the way, the custom visual hierarchy slicer has some problem, when I select the A and B, it will display the true data, but when I select the Grp_1, it will not display the true data.

Best Regards,

Teige

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.