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
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
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.