Forum Discussion

jludwick's avatar
jludwick
Frequent Visitor
4 years ago
Solved

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?
  • Hi jludwick ,

     

    If your data table is like this:

    You can follow these steps:

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

     2. Turn the single select of the slicer on

     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:

     

    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.

2 Replies