cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Helper I

## previous row calculations

Hi

i have a data of the following( for example)

year |  week in year | no. of people

2017        1                       500

2018        1                        300

2017        2                        100
2018        2                         50

*week in year is not derived from date but it based on some internal week counting in my organization

now - all i want to do is to put the current year vs previous year (with respeact to the same week in year no of people, meaning:

year   |  week in year      |   no of people  current year  |  no of pepole previous year

2018                  1                               300                                     500

2018                  2                                 50                                       100

so i could make a division calculation between those years with respect to this "week in year" coulmn ... but i can't make it! i tried with previousyear  function but it works only if i omit this "week in year" coulmn ...

i also wish to know how can i calc "previous year" if it was with a numric format and not date format (which then i can't use the previousyear function)

thanks!

1 ACCEPTED SOLUTION
Super User

@ellevy try this measure for previous year

``````Prev Year and Week =
VAR __currentYear = MAX ( Table[Year] )
VAR __prevYear = __currentYear - 1
VAR __currentWeek = MAX ( Table[Week in Year] )
RETURN
CALCULATE (
SUM ( Table[Number of People] ),
Table[Year] = __currentYear,
Table[Week in Year] = __currentWeek
) ``````

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

6 REPLIES 6
Super User

@ellevy try this

``````VAR __currentYear = YEAR ( Table[DateColumn] )
VAR __prevYear = __currentYear - 1``````

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Super User

@ellevy not sure why it is not working for you, but works for me

``````Prev =
VAR __selectedYear = MAX ( PRow[Year] )
VAR __prevYear = __selectedYear - 1
VAR __selectedWeek = MAX ( PRow[Week] )
RETURN
CALCULATE (
SUM ( PRow[People] ),
PRow[Year] = __prevYear,
PRow[Week] = __selectedWeek
)``````

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Super User

@ellevy try this measure for previous year

``````Prev Year and Week =
VAR __currentYear = MAX ( Table[Year] )
VAR __prevYear = __currentYear - 1
VAR __currentWeek = MAX ( Table[Week in Year] )
RETURN
CALCULATE (
SUM ( Table[Number of People] ),
Table[Year] = __currentYear,
Table[Week in Year] = __currentWeek
) ``````

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤

Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helper I

Hi parry2k

this looks promise but it only return me the same no of people meaning :

year | week in year | no of people current year | no of pepole previous year

2018        1                                    300                              300

2018       2                                     400                              400

the "year" is in date format (so i think the year-1 is not working there....)

Helper I

Ok i managed to make this work using :

``````CALCULATE (
SUM ( Table[Number of People] ),
Table[Year] = __PREVYEAR,
Table[Week in Year] = __currentWeek
) ``````

and i used a numric date column that i have (meaning integer format and not date format)

how can i do the:

``VAR __prevYear = __currentYear - 1``

using a date format column ?

Super User

@ellevy , Create a column

Week Year = [Year]*100 + [Week]

Create a week year table with year, week, and Week Year table.   Assume Date

Example measure

This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

For Week comparison you can create Week rank column in your table

Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYMM format

measures like

This Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
Last year Week= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -52)))

Announcements

#### New forum boards available in Real-Time Intelligence.

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

#### Fabric Monthly Update - May 2024

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

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors