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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
brinky
Helper IV
Helper IV

Dynamic measure date filter

Hello,

 

Trying to get sales and total for 2020 to date (i.e 21/09/2021 current date) in this matrix

 

I'm stuck till here 😏

 

PY Intake = 
 CALCULATE([Total],
FILTER('Date', 'Date'[YearAct]=YEAR(TODAY())-1))

Screenshot 2021-09-22 002740.png

1 ACCEPTED SOLUTION
moizsherwani
Continued Contributor
Continued Contributor

You need to have a "Day_Num" column in your date table which is simply DAY('Date'[Date])

 

TotalSalesCY =
CALCULATE ( [TotalSales], FILTER ( 'Date', 'Date'[Year] = YEAR ( TODAY () ) ) )

TotalSalesLY =
CALCULATE (
    [TotalSales],
    FILTER (
        'Date',
        'Date'[Year]
            = YEAR ( TODAY () ) - 1
            && 'Date'[Month_Num] <= MONTH ( TODAY () )
            && 'Date'[Day_Num] <= DAY ( TODAY() )
    )
)

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

View solution in original post

5 REPLIES 5
moizsherwani
Continued Contributor
Continued Contributor

Hi @brinky ,

 

See if this helps.

 

1) The Year filter on the page is from the Date Table

 

2) The bottom left table is just to show all the data that exists

 

3) The bottom right table is the summarized view which shows the data for the same period last year

 

moizsherwani_0-1632265483908.png

There must be a relationship between the data table and the date table

 

moizsherwani_1-1632265504487.png

 

Here are the two measures

 

TotalSales = SUM('Table'[Sale])

TotalSalesLY = CALCULATE([TotalSales],SAMEPERIODLASTYEAR('Date'[Date]))

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

Thanks for your reply.

I'm tring to obtain last year sale to date without any filters or slicers, this is my code for this year's sales data.

 

CALCULATE([Total],
     FILTER('Date','Date'[YearAct]=YEAR(NOW())))

 

Now I would like to have for same for last year.

 

Thank you

 

moizsherwani
Continued Contributor
Continued Contributor

There are plenty of way to do this (some possibly better) but this should get you the result.

 

Thanks,

 

Moiz

If this post helps, please "Accept" it as Solution to help other members find it.

TotalSalesCY =
CALCULATE ( [TotalSales], FILTER ( 'Date', 'Date'[Year] = YEAR ( TODAY () ) ) )

TotalSalesLY =
CALCULATE (
    [TotalSales],
    FILTER (
        'Date',
        'Date'[Year]
            = YEAR ( TODAY () ) - 1
            && 'Date'[Month_Num] <= MONTH ( TODAY () )
    )
)

 

 

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

Thanks Moiz,

Neraly there 😄 total should be 2,155,503 as per table below

 

Screenshot 2021-09-22 061942.png

moizsherwani
Continued Contributor
Continued Contributor

You need to have a "Day_Num" column in your date table which is simply DAY('Date'[Date])

 

TotalSalesCY =
CALCULATE ( [TotalSales], FILTER ( 'Date', 'Date'[Year] = YEAR ( TODAY () ) ) )

TotalSalesLY =
CALCULATE (
    [TotalSales],
    FILTER (
        'Date',
        'Date'[Year]
            = YEAR ( TODAY () ) - 1
            && 'Date'[Month_Num] <= MONTH ( TODAY () )
            && 'Date'[Day_Num] <= DAY ( TODAY() )
    )
)

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.