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
PANDAmonium
Resolver III
Resolver III

Matrix of Previous Year's Sales for Non Contiguous Dates

Hi All,

 

I'm trying to make a matrix of previous year's for non contiguous dates. This is going into a larger formula / matrix that uses this to set conditional formatting, but I've broken it down and this is the last piece I need to figure out.

 

Here's the forumla for my measure to calculate previous year's sales: 

Measure =
VAR PYEAR = MAX('Table'[Date].[Year]) - 1
VAR PVAL = CALCULATE(SUM('Table'[Value]), FILTER(ALLSELECTED('Table'), YEAR('Table'[Date]) = PYEAR))
RETURN PVAL
 
I included some screenshots on mock data. As you can see, this works when in a table for year only , but now if I want to add customer into the mix it will not reevaluate per customer but only show the sum for the year.
 
I've also tried 
Parallel Period = CALCULATE(SUM('Table'[Value]),PARALLELPERIOD('Table'[Date],-12,MONTH))

Works fine when evaluated against the total including split by customer, but within the table or matrix each row for year shows either 0 or blank (see second screenshot)

 

I think my brain is just mush at this point so any help is greatly appreciated. Thanks!

 

LYS.PNG

 

LYS2.PNG

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @PANDAmonium 

I have seen strange behavior when using time intelligent functions (PARALLELPERIOD) without a date table that extends from Jan 1st to Dec 31st.

You can add a basic date table using the following DAX code.

Dates = 
VAR DateRange = CALENDARAUTO()

RETURN
ADDCOLUMNS(
    DateRange,
    "Year",YEAR ( [Date] ),
    "Month", FORMAT ( [Date], "mmmm" ),
    "MonthNum", MONTH ( [Date] ),
    "Month Year", FORMAT ( [Date], "mmm-yyyy"),
    "MonthYearNum", YEAR ( [Date] ) * 100 + MONTH ( [Date] ),
    "Quarter Year", "Q" & FORMAT ( [Date], "q-yyyy" ),
    "QtrYearNum", YEAR ( [Date] ) * 100 + VALUE ( FORMAT ( [Date], "q" ) )
)

Then you link the Dates[Date] field into 'Table'[Date].

Next, under modeling, mark the Dates table as a date table.

Then try the measure like this.

PY Value = CALCULATE ( SUM('Table'[Value]), SAMEPERIODLASTYEAR ( DATES[Date] ) )

View solution in original post

4 REPLIES 4
jdbuchanan71
Super User
Super User

Hello @PANDAmonium 

I have seen strange behavior when using time intelligent functions (PARALLELPERIOD) without a date table that extends from Jan 1st to Dec 31st.

You can add a basic date table using the following DAX code.

Dates = 
VAR DateRange = CALENDARAUTO()

RETURN
ADDCOLUMNS(
    DateRange,
    "Year",YEAR ( [Date] ),
    "Month", FORMAT ( [Date], "mmmm" ),
    "MonthNum", MONTH ( [Date] ),
    "Month Year", FORMAT ( [Date], "mmm-yyyy"),
    "MonthYearNum", YEAR ( [Date] ) * 100 + MONTH ( [Date] ),
    "Quarter Year", "Q" & FORMAT ( [Date], "q-yyyy" ),
    "QtrYearNum", YEAR ( [Date] ) * 100 + VALUE ( FORMAT ( [Date], "q" ) )
)

Then you link the Dates[Date] field into 'Table'[Date].

Next, under modeling, mark the Dates table as a date table.

Then try the measure like this.

PY Value = CALCULATE ( SUM('Table'[Value]), SAMEPERIODLASTYEAR ( DATES[Date] ) )

Awesome, yeah, that worked. Thank you very much!

 

It feels so good just to finally blink, lol.

Actually...I might just need to switch it to a *:1 with a single direction filter. 1 min.

As soon as I split the table or matrix by customer it throws an error.

 

frown.PNG

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.