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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
HotelRM
Regular Visitor

Create LY Data Column Based on the Existing Filter Selected for TY

 

Let's start by saying this is my very first post in the forum - I'm very new to Power BI

 

To give you some background information, we use Fiscal Year with Financial Periods of 4 weeks, 4 weeks, 5 weeks cycles with yearly exceptions where a period which could be period 1 or 12 is a 6 weeks period every few years. Periods start on Sundays and end on Saturdays but (obviously) they don't start on the first day of the month nor they finish on the last date.

 

I created a CalendarTable as follows to be able to filter data by Year, Fical Period, Quarters, etc:

Calendar TableCalendar Table

I have a graph that shows that uses the following data an succesfully filters data using the above table:

 

DataTableDataTable

I would now like to create a Graph or a table that will display the daily data for LY's period as selected on a slicer, here's an example of part of the graphs currently displayed for Period 6 Year 2013:

 

Capture1.PNG

 

So I would like to add to each date a BAR corresponding to each of the dates but for Period 6 in 2012.

 

Could anyone please shade some light? 

 

 

14 REPLIES 14
v-ljerr-msft
Employee
Employee

Hi @HotelRM,

 

According to your description above, the total days for different fiscal years may vary, right?

 

If that is the case, you may need to calculate the total days between the same period last fiscal year and current fiscal year first, then you can use DATEADD function to calculate the daily data for LY's period. 

 

The formula below to create a measure to calculate the daily data for LY's period is for your reference.Smiley Happy

LY's Room Sold =
VAR currentYear =
    MAX ( 'Date'[FiscalYear] )
VAR currentPeriod =
    MAX ( 'Date'[FiscalPeriod] )
VAR daysSinceLY =
    CALCULATE (
        COUNTROWS ( 'Date' ),
        FILTER (
            ALL ( 'Date' ),
            ( 'Date'[FiscalYear]
                = currentYear - 1
                && 'Date'[FiscalPeriod] >= currentPeriod )
                || ( 'Date'[FiscalYear] = currentYear
                && 'Date'[FiscalPeriod] < currentPeriod )
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Data'[Room Sold] ),
        DATEADD ( 'Date'[Date], - daysSinceLY, DAY )
    )

 

Regards

Hi @v-ljerr-msft,

 

Many thanks for your quick response and suggestion, your solution would be great for to calculate the exact rooms sold for the same number of dates but I need something much simpler which I haven't been able to achieve yet.

 

All I need is to be able to get the rooms sold for the same period selected in the filter and for the "Previous Year" to the year currently selected in the filter. For example, if currenly my filter is on 2016 & Period 1 I would like to compare to rooms sold for Period 1 2015, regardless of how many weeks the period has in the different years.

 

 

Vvelarde
Community Champion
Community Champion

@HotelRM

 

hi, you can use sameperiodlastyear()

 

Example:

 

SalesLY=Calculate(Sum(TableDemo[SalesColumn]),Sameperiodlastyear(CalendarTable[DateColumn]))




Lima - Peru

Hi @Vvelarde,

 

Thanks for the sugestion but no, I can't use sameperiodlastyear() for fiscal periods as set in my calendar table, I wish it was that easy!

 

Many thanks anyway.

 

 

Vvelarde
Community Champion
Community Champion

@HotelRM

 

Ok, I think i have the solution, but take much time reproduce your tables.Please post sample Data.

 

Regards,




Lima - Peru

Hi Victor,

 

Not sure if I can upload them to the forum somehow but here they are in OneDrive:

FiscalCalendarSample 

DataSample

 

Many thanks for giving it a go!

 

 

Vvelarde
Community Champion
Community Champion

@HotelRM

 

Hi, please check if this is the desire result

 

LYRooms.png




Lima - Peru

@Vvelarde

 

Thanks Victor. Rooms Sold for 2007 - P11 should be 1,153. You can see it directly in your table if you change the filter to 2007; your Rooms Sold for 2007 should be the same result as Rooms Sold LY when the filter is on 2008.

 

Thanks,

 

Vvelarde
Community Champion
Community Champion

@HotelRM

 

I have a doubt

 

In your original post you want to see daily chart (Selected Year and Previous Year of each Day)

 

The sum by period is not exactly to a last year period because dates are different.

 

In 2007 period 11 start on 2/9 and in 2008 start in 31/08.

 

 

 

 

 

 




Lima - Peru

@Vvelarde correct, that's the difficulty, I want to compare the data for all dates that relate to a particular fiscal period in a given year (chosen in the filter) to the same fiscal period in a different year (in this case previous year). That's the reason why I had to create a calendar table with predetermined fiscal periods for fiscal years.

Vvelarde
Community Champion
Community Champion

@HotelRM

 

Sorry i don't follow you.

 

 

 

Don't know what is the desire result.

 

The compare is Daily? by Period?

 

Create a result table from Year 2008 and Period 11 and posted. (In Excel if you want)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 




Lima - Peru

@Vvelarde

 

I'm glad I mentioned I'm new to Power BI! perhaps it's not possible!

 

The result I want is just like the screenshot of the dashboard I posted at the begining. But to include in the daily stats bars side by side to compare LY (similar to what you did before - just with the correct data), and maybe some totals for the period on top of the dashboard (at the moment it only shows the current year).

 

In simple terms: daily rooms sold for the a fiscal period TY compared to the same fiscal period LY

 

 

As mentioned before, the data for LY (or for 2007 P11) is the same you would obtain for TY if you were to click on 2007 instead of 2008 - obviously in the graph I only need TY's dates or it could just be the number of the day (i.e. 1 to 28):

 

Capture.PNG

 

I guess the issue might be the dates themselves, perhaps if I had a column in the calendar with just the day of the fiscal year? i.e. 1 to 28 in this particular case then it might be easier. Anyway, I'm just thinking out loud as I don't really have a clue!

 

Anyway, thanks again for giving it a go. I'll probably have limited access over the weekend but would definetely pick it up next week if I don't get a chance in the next couple of days.

 

Vvelarde
Community Champion
Community Champion

@HotelRM

 

To close my questions

 

What is the problem in this chart.

 

LYRooms.png




Lima - Peru

It displays the incorrect data for LY.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.