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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
HarryB
Resolver I
Resolver I

previous year into a matrix table

Hello,

 

Can someone please send a sample pbi code or a dax code that will allow me to show 1. direct traffic 2. Organic into the previous year column. I am using a matrix table in PBI just wondered if anyone knows how to do this

 

HarryB_0-1710083936977.png

Thanks

1 ACCEPTED SOLUTION
lucadelicio
Super User
Super User

Hi,
try to create a measure like this:
DirectTrafficPY =
CALCULATE(
    SUM(DirectTraffic)
   ,SAMEPERIODLASTYEAR(<dates>)
 )
The same for the other measure.
If i help you mark this answer as Solution.

Luca D'Elicio

View solution in original post

5 REPLIES 5
v-kongfanf-msft
Community Support
Community Support

Hi @HarryB ,

 

The SAMEPERIODLASTYEAR function provided by @lucadelicio is a good choice.


Also in my testing, create a date table and put it in a one-to-many relationship with your data table. Then use the Dateadd function to find the value corresponding to the previous year.

Date = 
ADDCOLUMNS (
    CALENDAR ( DATE ( 2023, 01, 01 ), DATE ( 2024, 12, 31 ) ),
    "Year", YEAR ( [Date] ),
    "Quarter", ROUNDUP ( MONTH ( [Date] ) / 3, 0 ),
    "Month", FORMAT(MONTH ( [Date] ),"mmmm"),
    "Week", WEEKNUM ( [Date] ),
    "Year-Qur",
        YEAR ( [Date] ) & "Q"
            & ROUNDUP ( MONTH ( [Date] ) / 3, 0 ),
    "Year-Mon",
        YEAR ( [Date] ) * 100
            + MONTH ( [Date] ),
    "Year-Week",
        YEAR ( [Date] ) * 100
            + WEEKNUM ( [Date], 2 ),
    "Weekday", WEEKDAY ( [Date], 2 )
)

vkongfanfmsft_0-1710226589665.png

vkongfanfmsft_1-1710226612193.png

M_ = SUM('Table'[Direct Traffic])
Pre_year = CALCULATE([M_],DATEADD('Date'[Date],-1,YEAR))

vkongfanfmsft_2-1710226654817.png

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

@v-kongfanf-msft this is helpful thank you

lucadelicio
Super User
Super User

Hi,
try to create a measure like this:
DirectTrafficPY =
CALCULATE(
    SUM(DirectTraffic)
   ,SAMEPERIODLASTYEAR(<dates>)
 )
The same for the other measure.
If i help you mark this answer as Solution.

Luca D'Elicio

Hi @lucadelicio 

 

Thank you for your response.

I tried your solution but it did not work for me.

Would you happen to know what might be going on here My 'Source' is group with 2 sources.

HarryB_0-1710092141173.png

 

You forgt ) after SUM function

Luca D'Elicio

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

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.