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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Homer
New Member

Calculate Works until i use FILTER

Hello Guys

i'm learning DAX and i was trying to make a measure for Sales Last year with Calculate and Filter

this formula works :

 

 

 

 

 

 

Sales LY =CALCULATE([Sales CY],SAMEPERIODLASTYEAR(Date[Date]))

 

 

 

 

 

Sales LY =CALCULATE([Sales CY],SAMEPERIODLASTYEAR(Date[Date]))

 

But when i add FILTER to the measure give me the values from the current year like "Sales CY"

 

 

 

 

 

Sales LY = CALCULATE([Sales CY], Filter (Date, SAMEPERIODLASTYEAR (Date[Date]) ))

 

 

 

 

 

 

 

  • I already have a date filter on the page relative date in this year

  • the invoices Table and Date table are joined on the date of the creation of the invoice (createat)

  • Data Model

Capture.PNG

 

also i don't get the weird shapes inside the blue circles 

Any Help will much appreciated 

5 REPLIES 5
v-shex-msft
Community Support
Community Support

HI @Homer,

Have you tried to use the date function to manually define filter range instead of time intelligence functions?

Time Intelligence "The Hard Way" (TITHW)  

Regards,
Xiaoxin Sheng

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

@Homer , I hoping datedim is typo else

it need to like this ( I have not tested these)

 

Sales LY = CALCULATE([Sales CY], Filter (dim_date, dim_date[Date] in SAMEPERIODLASTYEAR (Date[Date]) ))

 

or

 

Sales LY = CALCULATE([Sales CY], Filter (Date, Date[Date] in SAMEPERIODLASTYEAR (Date[Date]) ))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hey amit 

i fixed  the type and i tried your formula but it returned nothing ...

 

new Sales LY = CALCULATE([Sales CY], Filter ('Date','Date'[Date] in SAMEPERIODLASTYEAR('Date'[Date])))

 

@Homer , I checked on My data. This is not working.

The reason is that I can think of, is that the Filter tries to remove the data from the context. In the case of time intelligence, that is not needed.

 

Refer this http://dataap.org/blog/2019/04/22/difference-between-calculate-with-and-without-filter-expression/

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

i checked the article about the difference and that's why i wanted to use "FILTER" in my case ..

It should work but i don't have any ideas why it's not 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.