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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jludwick
Frequent Visitor

Trying to Build a Prior Year DAX Function

Hi all,

 

I'm trying to build a prior year DAX function that interactively works with a timeframe filter. 

 

I have a timeframe table that assigns a 1 for a date ID that falls under "Current Week," "Current Month," "YTD," etc. I also have a -1 in the table to indicate the Current Week in the prior year, but I have these filtered out because the slicer would pull in both CY and PY if not. 

 

I have a DAX formula for volume that interacts perfectly with the timeframe filter:

calculate(
sum('Invoice Details'[Volume_Qty])).
 
How can I create something that pulls in prior year Volume in comparison to the Current Year indicator?
1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @jludwick ,

 

If your data table is like this:

vjianbolimsft_0-1656571321066.png

You can follow these steps:

1. Create a new table with all the options you need in the slicer.

vjianbolimsft_1-1656571321068.png

 2. Turn the single select of the slicer on

vjianbolimsft_2-1656571321069.png

 3. Then create a measure that calculate the Volume

calculate volumn =

SWITCH (

    MAX ( 'for slicer'[Value] ),

    "Prior Year",

        CALCULATE (

            SUM ( 'Invoice Details'[Volume_Qty] ),

            FILTER ( 'Invoice Details', [Column] = -1 )

        ),

    CALCULATE (

        SUM ( 'Invoice Details'[Volume_Qty] ),

        FILTER ( 'Invoice Details', [Column] = 1 )

    )

)

Final output:

vjianbolimsft_3-1656571321071.png

 

vjianbolimsft_4-1656571321073.png

If not, please provide me with more details about your table and your expected output or share me with your pbix file after removing sensitive data.

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

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

2 REPLIES 2
v-jianboli-msft
Community Support
Community Support

Hi @jludwick ,

 

If your data table is like this:

vjianbolimsft_0-1656571321066.png

You can follow these steps:

1. Create a new table with all the options you need in the slicer.

vjianbolimsft_1-1656571321068.png

 2. Turn the single select of the slicer on

vjianbolimsft_2-1656571321069.png

 3. Then create a measure that calculate the Volume

calculate volumn =

SWITCH (

    MAX ( 'for slicer'[Value] ),

    "Prior Year",

        CALCULATE (

            SUM ( 'Invoice Details'[Volume_Qty] ),

            FILTER ( 'Invoice Details', [Column] = -1 )

        ),

    CALCULATE (

        SUM ( 'Invoice Details'[Volume_Qty] ),

        FILTER ( 'Invoice Details', [Column] = 1 )

    )

)

Final output:

vjianbolimsft_3-1656571321071.png

 

vjianbolimsft_4-1656571321073.png

If not, please provide me with more details about your table and your expected output or share me with your pbix file after removing sensitive data.

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

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

ribisht17
Super User
Super User

@jludwick 

 

With calendar table you can use

 

Solved: Prior Year to Date Billable - Microsoft Power BI Community

 

Regards,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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