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
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
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.