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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
asl10
Helper I
Helper I

Show current and last year calculated column

Hi,

In a crystal report i have the following where i have a Year Group based on the below in order to see the revenue based on a user's input date on the reservation system and revenuew to come in based on customers reservation date. How can i replecated this with dax?

 

if {Rentals.Year} = Year (CurrentDate) then YEAR(CURRENTDATE)
else
if {Rentals.Input Date} < {@DateLastYear} and {Rentals.Year} = Year (CurrentDate)-1 then Year (CurrentDate)-1
else
0

 

**@DateLastYear is Year(CurrentDate)-1

1 ACCEPTED SOLUTION
technolog
Super User
Super User

To replicate the logic in DAX, you'll want to create a calculated column. Before diving into the DAX formula, it's important to understand that DAX has slightly different functions and syntax than what you'd find in Crystal Reports formulas.

Here's how you might translate your logic into DAX:

Year Group =
VAR CurrentYear = YEAR(TODAY())
VAR LastYear = CurrentYear - 1
RETURN
IF (
Rentals[Year] = CurrentYear,
CurrentYear,
IF (
Rentals[Input Date] < DATE(LastYear, 1, 1) && Rentals[Year] = LastYear,
LastYear,
0
)
)
In the above DAX formula:

I'm using the TODAY() function to get the current date.
The YEAR() function extracts the year portion of a date.
The DATE() function creates a date from year, month, and day components.
You'd add this calculated column to your Rentals table (or an equivalent table in your Power BI model).

After creating the column, you can then use the "Year Group" column to create your desired visualizations in Power BI.

View solution in original post

1 REPLY 1
technolog
Super User
Super User

To replicate the logic in DAX, you'll want to create a calculated column. Before diving into the DAX formula, it's important to understand that DAX has slightly different functions and syntax than what you'd find in Crystal Reports formulas.

Here's how you might translate your logic into DAX:

Year Group =
VAR CurrentYear = YEAR(TODAY())
VAR LastYear = CurrentYear - 1
RETURN
IF (
Rentals[Year] = CurrentYear,
CurrentYear,
IF (
Rentals[Input Date] < DATE(LastYear, 1, 1) && Rentals[Year] = LastYear,
LastYear,
0
)
)
In the above DAX formula:

I'm using the TODAY() function to get the current date.
The YEAR() function extracts the year portion of a date.
The DATE() function creates a date from year, month, and day components.
You'd add this calculated column to your Rentals table (or an equivalent table in your Power BI model).

After creating the column, you can then use the "Year Group" column to create your desired visualizations in Power BI.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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