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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
RavM_17
New Member

Year on year variance without dates

Hi,

 

I need to do a YoY variance based on a period number rather than date. I have a dates query however we report on periods and they move yearly so it's difficult to achieve by using the date functions. My dataset looks like below and I want to acheive the Var column. So it's P1 FY23 vs P1 FY22.

 

Total Emails Sent          Year       PeriodVar
500 FY22              1 
600 FY22              2 
650 FY22              3 
250 FY22              4 
750 FY23              1150%
130 FY23              222%
560 FY23             386%
560 FY23             4           224%

 

It would be great if I could do this on a cumulative basis as I intend on having a slicer for period. 

Any help is greatly appreciated.

3 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@RavM_17 You could create a DAX Index column for your table like this and then it should be easy. PBIX is attached below signature.

 

DAX Index = 
    VAR __TableText = CONCATENATEX(ALL('Table'),[Year] & ":" & [Period],"|",[Year]&[Period],ASC)
    VAR __Count = COUNTROWS(ALL('Table'))
    VAR __Table = 
        ADDCOLUMNS(
            GENERATESERIES(1, __Count,1),
            "__Year",LEFT(PATHITEM(__TableText,[Value]),5),
            "__Period",RIGHT(PATHITEM(__TableText,[Value]),1) + 0
        )
    VAR __Result = MAXX(FILTER(__Table,[__Year] = [Year] && [__Period] = [Period]),[Value])
RETURN
    __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

mangaus1111
Solution Sage
Solution Sage

Hi @RavM_17 ,

sorry I don´t understand how you have calculated the variance of 150%  in your example

View solution in original post

mangaus1111
Solution Sage
Solution Sage

Hi @RavM_17 ,

see my pbi file. I havee added a column [Year Number] in Power Query and then the calculated column [Var] in DAX.

https://1drv.ms/u/s!Aj45jbu0mDVJiz0wZas9jKH1XGrM?e=GhXI2c

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

View solution in original post

4 REPLIES 4
PaulDBrown
Community Champion
Community Champion

Another way is to add a date column to your fact table. It may seem an overkill, but it allows for the use of time intelligence functions

 

Period Date =
VAR _Year =
    RIGHT ( fTable[Year], 2 )
VAR _Period =
    SWITCH ( fTable[Period], 4, 12, 3, 9, 2, 6, 1, 3 )
RETURN
    DATE ( 2000 + _Year, _Period, 1 )

 

ft date.jpgand then create a calendar table

 

Calendar Table =
ADDCOLUMNS (
    CALENDAR ( MIN ( fTable[Period Date] ), MAX ( fTable[Period Date] ) ),
    "MonthNum", MONTH ( [Date] ),
    "Month", FORMAT ( [Date], "MMM" ),
    "dYear", YEAR ( [Date] ),
    "dFYear", "FY" & RIGHT ( YEAR ( [Date] ), 2 ),
    "dPeriod", QUARTER ( [Date] )
)

 

cal table.jpg

 

model.jpg

Then

 

% vs PY Emails =
VAR _PY =
    CALCULATE ( [Sum emails sent], SAMEPERIODLASTYEAR ( 'Calendar Table'[Date] ) )
RETURN
    DIVIDE ( [Sum emails sent], _PY )

 

and

 

% Cumulative vs Cumul PY =
VAR _CY =
    CALCULATE ( [Sum emails sent], DATESYTD ( 'Calendar Table'[Date] ) )
VAR _CumulPY =
    CALCULATE (
        [Sum emails sent],
        FILTER (
            ALL ( 'Calendar Table' ),
            'Calendar Table'[dPeriod] <= MAX ( 'Calendar Table'[dPeriod] )
                && 'Calendar Table'[dYear]
                    = MAX ( 'Calendar Table'[dYear] ) - 1
        )
    )
RETURN
    DIVIDE ( _CY, _CumulPY )

 

will get you

result.jpgSample PBIX attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






mangaus1111
Solution Sage
Solution Sage

Hi @RavM_17 ,

see my pbi file. I havee added a column [Year Number] in Power Query and then the calculated column [Var] in DAX.

https://1drv.ms/u/s!Aj45jbu0mDVJiz0wZas9jKH1XGrM?e=GhXI2c

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

mangaus1111
Solution Sage
Solution Sage

Hi @RavM_17 ,

sorry I don´t understand how you have calculated the variance of 150%  in your example

Greg_Deckler
Community Champion
Community Champion

@RavM_17 You could create a DAX Index column for your table like this and then it should be easy. PBIX is attached below signature.

 

DAX Index = 
    VAR __TableText = CONCATENATEX(ALL('Table'),[Year] & ":" & [Period],"|",[Year]&[Period],ASC)
    VAR __Count = COUNTROWS(ALL('Table'))
    VAR __Table = 
        ADDCOLUMNS(
            GENERATESERIES(1, __Count,1),
            "__Year",LEFT(PATHITEM(__TableText,[Value]),5),
            "__Period",RIGHT(PATHITEM(__TableText,[Value]),1) + 0
        )
    VAR __Result = MAXX(FILTER(__Table,[__Year] = [Year] && [__Period] = [Period]),[Value])
RETURN
    __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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