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
lordsriram
Frequent Visitor

SWITCH OR IF STATEMENT for PY SHIPPED AMOUNT

I am trying to get the following in a calculated measure value

 

When the Year is current year - I want the calculation to be

 

 

CALCULATE(SUM('TRDTA PWRBI_SALES'[SHIPPED AMOUNT]),DATESBETWEEN( 'INVOICE DATE'[INVOICE DATE].[Date],DATE (YEAR(TODAY())-1, "1", "1"),DATE (YEAR(TODAY())-1, MONTH(TODAY()), DAY(TODAY())))

 

else I want the calculation to be 

 

 

CALCULATE(SUM('TRDTA PWRBI_SALES'[SHIPPED AMOUNT]), SAMEPERIODLASTYEAR('INVOICE DATE'[INVOICE DATE].[Date]))

 

 

When it is current year, I want to compare only till date and other years, I want to use whole year. 

 

Please let me know if there is a better way to do this

 

Thanks

Sriram

1 ACCEPTED SOLUTION

HI @lordsriram,

 

If you mean a measure contains two calculate logic based on 'today' function, you can try to use below measure formula:

Dyanmic Measure = 
VAR currDate =
    MAX ( Invoice[INVOICE DATE] )
RETURN
    IF (
        YEAR ( currDate ) = YEAR ( TODAY () ),
        CALCULATE (
            SUM ( 'SALES'[SHIPPED_AMOUNT] ),
            FILTER (
                ALLSELECTED ( Sales ),
                [INVOICE_DATE]
                    >= DATE ( YEAR ( TODAY () ) - 1, 1, 1 )
                    && [INVOICE_DATE]
                        <= DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
            )
        ),
        CALCULATE (
            SUM ( 'Sales'[SHIPPED_AMOUNT] ),
            FILTER (
                ALLSELECTED ( 'Sales' ),
                YEAR ( [INVOICE_DATE] )
                    = YEAR ( currDate ) - 1
            )
        )
    )


Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
zoloturu
Memorable Member
Memorable Member

@lordsriram,

 

Please post:

 

1. Sample data.

2. Explanation of a logic of these measures. 

 

Regards,
Ruslan

@zoloturu

 

sample data

 

Attached link has the file with the sample data

 

I am trying to get the total of shipped amount for each year and for the current year - I want the Previous year sales to be only for the dates till current date. For the rest of the years, i want to use the whole year for calculation. I want this to be in PY Shipped amount field and was trying to change the calculation display based on the year from invoice date table. I can do this in 2 different measures but the display to the user is a bit confusing.

 

Thanks

Sriram

HI @lordsriram,

 

If you mean a measure contains two calculate logic based on 'today' function, you can try to use below measure formula:

Dyanmic Measure = 
VAR currDate =
    MAX ( Invoice[INVOICE DATE] )
RETURN
    IF (
        YEAR ( currDate ) = YEAR ( TODAY () ),
        CALCULATE (
            SUM ( 'SALES'[SHIPPED_AMOUNT] ),
            FILTER (
                ALLSELECTED ( Sales ),
                [INVOICE_DATE]
                    >= DATE ( YEAR ( TODAY () ) - 1, 1, 1 )
                    && [INVOICE_DATE]
                        <= DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
            )
        ),
        CALCULATE (
            SUM ( 'Sales'[SHIPPED_AMOUNT] ),
            FILTER (
                ALLSELECTED ( 'Sales' ),
                YEAR ( [INVOICE_DATE] )
                    = YEAR ( currDate ) - 1
            )
        )
    )


Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.