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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
admin11
Memorable Member
Memorable Member

How to modify my expression using Var , so that i can insert YTD , LYTD , GP%

Hi All

 
I have below expression working fine , it will return total sales amount :-
_amount_select3 =
SWITCH(
SELECTEDVALUE(SliceTable[Slice]),
"BRAND_C",IF(ISINSCOPE(summrizetable2[rank]),
CALCULATE(SUM('SALES'[sales]),FILTER(ALLSELECTED('SALES'),[BRAND_C]=MAX('summrizeTable1'[BRAND_C]))), SUM('SALES'[sales])))
 
May i know how to modify the above expression using Var like below :-
_amount_select3 =
VAR1=SUM('SALES'[sales]
SWITCH(
SELECTEDVALUE(SliceTable[Slice]),
"BRAND_C",IF(ISINSCOPE(summrizetable2[rank]),
CALCULATE(VAR1),FILTER(ALLSELECTED('SALES'),[BRAND_C]=MAX('summrizeTable1'[BRAND_C]))), VAR1)))
 
 Hope some one can help me advies me on above expression.
 
Paul
1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @admin11 ,

 

It would be like this:-

_amount_select3 =
VAR VAR1 =
    SUM ( 'SALES'[sales] )
RETURN
    SWITCH (
        SELECTEDVALUE ( SliceTable[Slice] ),
        "BRAND_C",
            IF (
                ISINSCOPE ( summrizetable2[rank] ),
                CALCULATE ( VAR1 ),
                FILTER (
                    ALLSELECTED ( 'SALES' ),
                    [BRAND_C] = MAX ( 'summrizeTable1'[BRAND_C] )
                )
            ),
        VAR1
    )

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

9 REPLIES 9
Samarth_18
Community Champion
Community Champion

Hi @admin11 ,

 

It would be like this:-

_amount_select3 =
VAR VAR1 =
    SUM ( 'SALES'[sales] )
RETURN
    SWITCH (
        SELECTEDVALUE ( SliceTable[Slice] ),
        "BRAND_C",
            IF (
                ISINSCOPE ( summrizetable2[rank] ),
                CALCULATE ( VAR1 ),
                FILTER (
                    ALLSELECTED ( 'SALES' ),
                    [BRAND_C] = MAX ( 'summrizeTable1'[BRAND_C] )
                )
            ),
        VAR1
    )

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18 

i get error msg.

admin11_0-1642503186628.png

 

@admin11 ,Please try this:-

 

_amount_select3 =
SWITCH (
    SELECTEDVALUE ( SliceTable[Slice] ),
    "BRAND_C",
        IF (
            ISINSCOPE ( summrizetable2[rank] ),
            CALCULATE (
                VAR1,
                FILTER (
                    ALLSELECTED ( 'SALES' ),
                    [BRAND_C] = MAX ( 'summrizeTable1'[BRAND_C] )
                )
            ),
            VAR1
        )
)

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18 

 

i Just notice that all row return same value. 

admin11_0-1642504882151.png

Hope you can advise me where go wrong ?

 

Paul

Small correction. Please try this:-

_amount_select3 =
VAR VAR1 =
    SUM ( 'SALES'[sales] )
RETURN
    SWITCH (
        SELECTEDVALUE ( SliceTable[Slice] ),
        "BRAND_C",
            IF (
                ISINSCOPE ( summrizetable2[rank] ),
                CALCULATE (
                    VAR1,
                    FILTER (
                        ALLSELECTED ( 'SALES' ),
                        [BRAND_C] = MAX ( 'summrizeTable1'[BRAND_C] )
                    )
                )
            ),
        VAR1
    )

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18 

Thank you for your help , but still the same.

@admin11 is it possible for you to share your PBIX file after removing sensitive data since its bit difficult to answer without seeing data. 

Is it working fine without variable?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18 

wow you are very good . thank you very much.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.