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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

how to transform the data use DAX

Hi, Here is my data any and I need to create a visual that show the data both this year the previous year, but the x-axis should be current year, so first I need to transform the data, and the result of the data of current year and previous year should be in the same row, do you have any ideas how to transform the Rev Last of 2021 to 2022? Thank you.

null_0-1668577823003.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1669110937790.png

2. create a measure with below dax formula

Measure =
VAR cur_ym =
    SELECTEDVALUE ( 'Table'[year_month] )
VAR cur_year =
    INT ( LEFT ( cur_ym, 4 ) )
VAR cur_month =
    INT ( RIGHT ( cur_ym, 2 ) )
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        INT ( LEFT ( 'Table'[year_month], 4 ) = cur_year - 1 )
    )
VAR _val =
    CALCULATE (
        MAX ( 'Table'[Rev Last] ),
        ALL ( 'Table' ),
        INT ( LEFT ( 'Table'[year_month], 4 ) ) = cur_year - 1,
        INT ( RIGHT ( 'Table'[year_month], 2 ) ) = cur_month
    )
RETURN
    _val

3. add a table visual with fields and measure

vbinbinyumsft_1-1669111053814.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
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

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1669110937790.png

2. create a measure with below dax formula

Measure =
VAR cur_ym =
    SELECTEDVALUE ( 'Table'[year_month] )
VAR cur_year =
    INT ( LEFT ( cur_ym, 4 ) )
VAR cur_month =
    INT ( RIGHT ( cur_ym, 2 ) )
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        INT ( LEFT ( 'Table'[year_month], 4 ) = cur_year - 1 )
    )
VAR _val =
    CALCULATE (
        MAX ( 'Table'[Rev Last] ),
        ALL ( 'Table' ),
        INT ( LEFT ( 'Table'[year_month], 4 ) ) = cur_year - 1,
        INT ( RIGHT ( 'Table'[year_month], 2 ) ) = cur_month
    )
RETURN
    _val

3. add a table visual with fields and measure

vbinbinyumsft_1-1669111053814.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

SwayamSinha
Microsoft Employee
Microsoft Employee

SwayamSinha_0-1668579590520.png

If you looking for something as above then its as simple as the below code:

PyQty = Calculate (Sum(Order_Details[Quantity]),DATEADD('Date'[Date],-1,Year))

 

Anonymous
Not applicable

Thanks! the date column type is text so it sees this function did not solve the problem directly

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.