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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
swasim
Helper I
Helper I

Need Help : Measure to Calculate Sum from 1 column and Sum Balance from other column ignoring Slicer

I need help to compute a Column called Total which is a measure.  I have 2 slicer Country and Date . if Country is "India" alone . I  hve 2 conditions

1) Sum the Loan by Comp and also country

2) Sum the Balance column by Comp but excluding the slicer Country if its India alone. I have attached the Input data and expected result showing how to arrive.

 

Challenge is SUM Balance for All the country If India is Selected .  I am also using Dimension table for Country for Slicer

 

Fact Table 

CountryCompDateLoanBalance
IndiaAccen7/31/202310 
USAMicrosoft7/31/20235 
JapanApple7/31/202302
ChinaGoogle7/31/202302
IndiaMicrosoft7/31/20232 
USAMicrosoft7/31/20235 
IndiaApple7/31/202305
ChinaAccen7/31/2023 5
ChinaAccen7/31/2023 5

 

Expected Result :

swasim_2-1696176127151.png

 

@tamerj1  @technolog 

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @swasim ,

You can create the measures as below to get it, please find the details in the attachment.

Measure = 
VAR _selcountry =
    SELECTEDVALUE ( 'Countries'[Country] )
VAR _comps =
    CALCULATETABLE (
        VALUES ( 'Table'[Comp] ),
        FILTER ( 'Table', 'Table'[Country] = _selcountry )
    )
VAR _loan =
    CALCULATE (
        SUM ( 'Table'[Loan] ),
        FILTER ( 'Table', 'Table'[Country] = _selcountry )
    )
VAR _balance =
    CALCULATE (
        SUM ( 'Table'[Balance] ),
        FILTER (
            'Table',
            IF ( _selcountry = "India", 1 = 1, 'Table'[Country] = _selcountry )
                && 'Table'[Comp] IN _comps
        )
    )
RETURN
    _loan + _balance
Sum of Loan = SUMX(VALUES('Table'[Comp]),[Measure])

vyiruanmsft_0-1696303410871.png

Best Regards

Community Support Team _ Rena
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

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @swasim ,

You can create the measures as below to get it, please find the details in the attachment.

Measure = 
VAR _selcountry =
    SELECTEDVALUE ( 'Countries'[Country] )
VAR _comps =
    CALCULATETABLE (
        VALUES ( 'Table'[Comp] ),
        FILTER ( 'Table', 'Table'[Country] = _selcountry )
    )
VAR _loan =
    CALCULATE (
        SUM ( 'Table'[Loan] ),
        FILTER ( 'Table', 'Table'[Country] = _selcountry )
    )
VAR _balance =
    CALCULATE (
        SUM ( 'Table'[Balance] ),
        FILTER (
            'Table',
            IF ( _selcountry = "India", 1 = 1, 'Table'[Country] = _selcountry )
                && 'Table'[Comp] IN _comps
        )
    )
RETURN
    _loan + _balance
Sum of Loan = SUMX(VALUES('Table'[Comp]),[Measure])

vyiruanmsft_0-1696303410871.png

Best Regards

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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors