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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
GauthamBR
Frequent Visitor

How to calculate Same Day last year sales & Same day, same time last year sales

I need to calculate - Same Day last year sales & Same day, same time last year sales. I don't want to use SAMEPERIOD DAX function because my clients day counting is different. Attaching an image for reference.

First I need to set FLAG as Y or N depending on whether the store had sales on same day last year and also I need to calculate the sales amount for those with Y.

 

Thanks in advance!

 

Capture.PNG

2 ACCEPTED SOLUTIONS
Zubair_Muhammad
Community Champion
Community Champion

@GauthamBR

 

For flagging try this column

 

Flag Column =
VAR CurrentYear = YEAR ( TODAY () )
VAR CurrentRowDate = TableB[Date]
VAR check =
    CALCULATE (
        COUNTROWS ( TableB ),
        FILTER (
            ALLEXCEPT ( TableB, TableB[StoreID] ),
            TableB[Date]
                = DATE ( YEAR ( CurrentRowDate ) - 1, MONTH ( CurrentRowDate ), DAY ( CurrentRowDate ) )
        )
    )
RETURN
    IF (
        YEAR ( CurrentRowDate ) = CurrentYear
            && Check > 0,
        "Y",
        IF ( YEAR ( CurrentRowDate ) = CurrentYear, "N" )
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @GauthamBR,

 

For Table A, you could try with the fomula below which I have modified from @Zubair_Muhammad.

 

 

LastYearSales = 
VAR CurrentYear =
    YEAR ( TODAY () )
VAR CurrentRowDate = 'TableA'[Date]
RETURN
    IF (
        TableA[Flag] = "Y",
        CALCULATE (
            max ( TableA[Sales] ),
            FILTER (
                 ALL(TableA),
                TableA[Date]
                    = DATE ( YEAR ( CurrentRowDate ) - 1, MONTH ( CurrentRowDate ), DAY ( CurrentRowDate ) )
            )
        )
    )

Here is the result.

 

Capture.PNG

 

For the table B, I still have a little confused about the LastYr Sales, why the result is 10 and 0. What is the logic?

 

Please describe your scenario in more details.

 

 

Best Regards,

Cherry

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

5 REPLIES 5
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @GauthamBR,

 

For Table A, you could try with the fomula below which I have modified from @Zubair_Muhammad.

 

 

LastYearSales = 
VAR CurrentYear =
    YEAR ( TODAY () )
VAR CurrentRowDate = 'TableA'[Date]
RETURN
    IF (
        TableA[Flag] = "Y",
        CALCULATE (
            max ( TableA[Sales] ),
            FILTER (
                 ALL(TableA),
                TableA[Date]
                    = DATE ( YEAR ( CurrentRowDate ) - 1, MONTH ( CurrentRowDate ), DAY ( CurrentRowDate ) )
            )
        )
    )

Here is the result.

 

Capture.PNG

 

For the table B, I still have a little confused about the LastYr Sales, why the result is 10 and 0. What is the logic?

 

Please describe your scenario in more details.

 

 

Best Regards,

Cherry

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

Thanks much for the help @Zubair_Muhammad and @v-piga-msft !

 

@v-piga-msft Table B's updated screenshot is attached

 

The Flagging concept is similar to Table A. But LastYearSales needs to be calculated based on " Same day - Same time - last year"

 

TableB.PNG

 

Hi @GauthamBR,

 

The formula from @Zubair_Muhammad could help you get the correct result for Table B.

 

Capture.PNG

 

Best  Regards,

Cherry

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

@GauthamBR

 

For flagging try this column

 

Flag Column =
VAR CurrentYear = YEAR ( TODAY () )
VAR CurrentRowDate = TableB[Date]
VAR check =
    CALCULATE (
        COUNTROWS ( TableB ),
        FILTER (
            ALLEXCEPT ( TableB, TableB[StoreID] ),
            TableB[Date]
                = DATE ( YEAR ( CurrentRowDate ) - 1, MONTH ( CurrentRowDate ), DAY ( CurrentRowDate ) )
        )
    )
RETURN
    IF (
        YEAR ( CurrentRowDate ) = CurrentYear
            && Check > 0,
        "Y",
        IF ( YEAR ( CurrentRowDate ) = CurrentYear, "N" )
    )

Regards
Zubair

Please try my custom visuals

@GauthamBR

 

Then Lastyearsales

 

LastYearSales =
VAR CurrentYear =
    YEAR ( TODAY () )
VAR CurrentRowDate = TableB[Date]
RETURN
    IF (
        TableB[Flag] = "Y",
        CALCULATE (
            SUM ( TableB[Sales] ),
            FILTER (
                ALLEXCEPT ( TableB, TableB[StoreID], TableB[Hour] ),
                TableB[Date]
                    = DATE ( YEAR ( CurrentRowDate ) - 1, MONTH ( CurrentRowDate ), DAY ( CurrentRowDate ) )
            )
        )
    )

Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.