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
jwin2424
Resolver I
Resolver I

Displayed selected year and prior year on slicer

Hello. 

 

I am trying to get it so my clustered bar chart will show both the selected year on the slicer AND the prior year. I found a formula and a how-to online (Here), but it doesn't seem to be working. 

 

On my chart, you can see I have the slicer selected for 2021, but it is not showing 2021 and 2020 on the graph. 

 

jwin2424_0-1641429461161.png

 

1. I created a calculated table using this formula:

jwin2424_1-1641429553177.png

2. I then created a relationship between this table and my Dim Calendar table. 

3. I used the newly created table year for my slicer (replacing the Dim Calendar year)

4. I created a new measure

 

jwin2424_2-1641429670539.png

5. I filtered the slicer with the new measure 

jwin2424_3-1641429742418.png

 

My calendar range is from 1995-2030 if that makes a difference.

 

Thanks!

 

1 ACCEPTED SOLUTION
samdthompson
Memorable Member
Memorable Member

Hello, the formula above will work with a wee change to from week to month, in this case:

 

Measure 2:

Net US Revenue PY = 

VAR _CurrentPeriod = SELECTEDVALUE( Dates[Fiscal Month] )

VAR _CurrentYear = SELECTEDVALUE( Dates[Fiscal Year] )

VAR _Result =

SUMX(

FILTER( ALL( Dates ),

Dates[Fiscal Month] = _CurrentPeriod &&

Dates[Fiscal Year] = _CurrentYear - 1 ),

[Net US Revenue] )

RETURN

_Result

 

 

// if this is a solution please mark as such. Kudos always appreciated.

View solution in original post

12 REPLIES 12
samdthompson
Memorable Member
Memorable Member

Hello, the formula above will work with a wee change to from week to month, in this case:

 

Measure 2:

Net US Revenue PY = 

VAR _CurrentPeriod = SELECTEDVALUE( Dates[Fiscal Month] )

VAR _CurrentYear = SELECTEDVALUE( Dates[Fiscal Year] )

VAR _Result =

SUMX(

FILTER( ALL( Dates ),

Dates[Fiscal Month] = _CurrentPeriod &&

Dates[Fiscal Year] = _CurrentYear - 1 ),

[Net US Revenue] )

RETURN

_Result

 

 

// if this is a solution please mark as such. Kudos always appreciated.

Sorry one more question! I know with selectedvalues it does not show a total. Is there a workaround to see the grand total?

jwin2424_0-1641504039331.png

 

Hello, something like:

 

Net US Revenue PY = 

 

VAR _CurrentPeriod = SELECTEDVALUE( Dates[Fiscal Month] )

VAR _CurrentYear = SELECTEDVALUE( Dates[Fiscal Year] )

VAR _Result =

SUMX(

FILTER( ALL( Dates ),

Dates[Fiscal Month] = _CurrentPeriod &&

Dates[Fiscal Year] = _CurrentYear - 1 ),

[Net US Revenue] )

RETURN

IF( HASONEVALUE(Dates[Fiscal Month]) , _Result ,

SUMX(FILTER( ALL( Dates ),Dates[Fiscal Month] = _CurrentPeriod &&Dates[Fiscal Year] = _CurrentYear - 1 ),[Net US Revenue] ) , _Result)

 

// if this is a solution please mark as such. Kudos always appreciated.

Came back with "IF function has too many arguements. It can only support 3." It's not a huge deal. I am turning this into a clustered column chart instead. I really just wanted the ability to do current yr vs prior yr which you solved for me. I will find another means to show YoY grand total and go a different route. I appreciate the help!

Not quite: 

 

jwin2424_0-1641507875418.png

 

Huh, Weird, try this:

VAR _CurrentPeriod = SELECTEDVALUE( Dates[Fiscal Month] )

VAR _CurrentYear = SELECTEDVALUE( Dates[Fiscal Year] )

VAR _Result =

SUMX(

FILTER( ALL( Dates ),

Dates[Fiscal Month] = _CurrentPeriod &&

Dates[Fiscal Year] = _CurrentYear - 1 ),

[Net US Revenue] )

RETURN

IF( HASONEVALUE(Dates[Fiscal Month]) , _Result ,

SUMX(FILTER( ALL( Dates ),Dates[Fiscal Month] = _CurrentPeriod &&Dates[Fiscal Year] = _CurrentYear - 1 ),[Net US Revenue] ) , _Result)

// if this is a solution please mark as such. Kudos always appreciated.

I must have mistyped something when doing this, but I entered it in again and it works exactly as needed. Thank you!

samdthompson
Memorable Member
Memorable Member

Hello, make the sure you are using a date hierarchy on the x axis (Yr, Mth, Day). This solution will work unless you are using a 544, 445 or 454 wk pattern. If you are doing that there needs to be a little finessing to the formulas. There are a bunch of ways to go about this but my go to is Ken Puls's one which goes back to a fit for purpose calendar: Creating a custom calendar in Power QueryThe Excelguru Blog. 

 

The 2nd measure  you wrtoe for the PY is then changed (you will need to fix the column names and table name to what ever the new date table has):

 

Measure 2:

Net US Revenue PY = 

VAR _CurrentPeriod = SELECTEDVALUE( Dates[WeekOfYear] )

VAR _CurrentYear = SELECTEDVALUE( Dates[Year] )

VAR _Result =

SUMX(

FILTER( ALL( Dates ),

Dates[WeekOfYear] = _CurrentPeriod &&

Dates[Year] = _CurrentYear - 1 ),

[Net US Revenue] )

RETURN

_Result

 

Id really like to see MS make 445, calendars an easier thing to grapple with since they are currently much harder than they really should be.

 

// if this is a solution please mark as such. Kudos always appreciated.

It seems like you are on the right path, but I decided against the slicer because I want the slicer to relate to all my tables, but I only want one table to show prior year. I am trying to get a formula in the table instead of the slicer now. Something like what @samdthompson mentioned. 

 

When I used sam's formula, it did exactly what I wanted EXCEPT it returned the entire month (Jan 1st to Jan 31st) instead of returning to me the fiscal period (Jan 1st to Jan 28th). It doesn't appear that time intellegence formulas will work because it can only refer to DATE formats. 

 

Can I do something similiar to the above where I grab the sum from prior period?

 

This is my goal. Something that says give me the sum from the same fiscal month from the fiscal year - 1? insteaf of referencing the DATE column?

 

NUMBER FORMATNUMBER FORMAT  
Fiscal YearFiscal MonthTotal RevenueTotal PY Revenue
20201$1,524,856.00 
20202$652,158.00 
20203$621,835.00 
20204$1,548,265.00 
20205$1,234,658.00 
20206$987,652.00 
20207$921,458.00 
20208$1,206,589.00 
20209$985,448.00 
202010$998,635.00 
202011$1,689,547.00 
202012$1,489,756.00 
20211$968,523.00$1,524,856.00
20212$879,546.00$652,158.00
20213$895,741.00$621,835.00
20214$1,659,876.00$1,548,265.00
20215$1,789,548.00$1,234,658.00
20216$1,235,684.00$987,652.00
20217$897,546.00$921,458.00
20218$789,485.00$1,206,589.00
20219$986,341.00$985,448.00
202110$1,635,874.00$998,635.00
202111$1,659,874.00$1,689,547.00
202112$987,685.00$1,489,756.00

 

samdthompson
Memorable Member
Memorable Member

Hello, why not use the SAMEPERIODLASTYEAR()? So something like:

 

Measure 1:

Net US Revenue = SUM(Sales[Net US Revenue])

 

Measure 2:

Net US Revenue PY = CALCULATE([Net US Revenue], SAMEPERIODLASTYEAR('Dim Tek Calendar'[Dates]))

 

That way you select say 2021 and the 2021 measure for [Net US Revenue] will show up along with the [Net US Revenue PY] as a separate bunch of columns for the 2021 months

 

 

// if this is a solution please mark as such. Kudos always appreciated.

Ok. This actually did work EXCEPT there is one issues. The sample period is summurizing the data based on the DATE, and the sales are based on FISCAL dates. When I sum the totals, it sums the sales based on the fiscal date (which is what I want), but when I do the sample period, it sums the sales based on the calendar date. I had to create a table for the fiscal date month, quarter, etc. and the format is a number (not a date), so i can't reference it in the measure without receiving an error (because it is not a date). Is there another way?

I don't quite understand the instructions. I replaced the Net USD with Measure 1 in the "Value" area of the chart. Where does Measure 2 go? I can't put it on the clustered chart with Measure 1. 

 

Thanks!

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.