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
Anonymous
Not applicable

Prior and Current Year total sales calculation direct query

Hi Gurus,

 

I have connected to  HANA DB direct query. I need help in calculating  Previous Year & Current Year total sales.

I try this formula from Pragmaticworks.com cheat sheet but I'm getting an error. Please help

 

Prior Year Profit (Direct Query)

Calculates Profit for all days in the Year prior to the last year in the selection. Limited to the last day of the selection.

 Prior Year Profit = 
CALCULATE (
      [Profit],
      FILTER (
           ALL ( 'DateTable' ),
                'DateTable'[Year] = MAX ( 'DateTable'[Year] ) - 1 
   )
)

 

Thanks

PC

1 ACCEPTED SOLUTION

Hey,

 

this simply says that the columns have different data types, make your that both columns have the same data type.

 

I'm wondering if it's a typo that you use the column Destination.

 

Nevertheless, mark the column and in the Modeling menu you will find "Data type" in the formatting ribbon.

 

As you subtract -1 to get the prior year, the data type should be numeric. Also consider that it might be necessary to use this snippet 

YEAR(MAX('tablename'[date column))

if the column on the right hand side of the filter condition has the data type date

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

5 REPLIES 5
TomMartens
Super User
Super User

Hey,

 

can you please provide the error message you get.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

It creates, but when you drag to the canvas that's when l get the error.

 

Capture.PNG

 

Hey,

 

this simply says that the columns have different data types, make your that both columns have the same data type.

 

I'm wondering if it's a typo that you use the column Destination.

 

Nevertheless, mark the column and in the Modeling menu you will find "Data type" in the formatting ribbon.

 

As you subtract -1 to get the prior year, the data type should be numeric. Also consider that it might be necessary to use this snippet 

YEAR(MAX('tablename'[date column))

if the column on the right hand side of the filter condition has the data type date

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

Yes the Destination was a typo, but more so the 

 

data type 

LIKE BTW is a whole number

 

 WADA YEAR  is Text 

I can't change it to whole number

 

 

Thanks

PC

 

Anonymous
Not applicable

Thanks for your help

 

 

So this will be my new formula.

 

Prior Year =CALCULATE (
[Profit],
FILTER (
ALL ( 'DateTable' ),
YEAR(MAX('tablename'[date column)) - 1
)
)


Current Year =CALCULATE (
[Profit],
FILTER (
ALL ( 'DateTable' ),
YEAR(MAX('tablename'[date column))
)
)

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.