Forum Discussion

ATYB9's avatar
ATYB9
New Member
3 years ago
Solved

Data slicing - multiple years

Hello,

 

I am fairly new to Power BI and I am trying to use slicer to apply in a dynamic way so that the visuals on the same page show the relevant data for the particular year.

 

See below my data from Excel file with two tabs (seem to be unable to attach the file for some reason):

 

Power BI report link 

Excel file link 

 

First tab "Summary details"

IDDraft/FinalEntity NameCurrency of dataPeriod End
Entity ABC 31/12/2021DraftEntity ABCGBP test 202131/12/2021
Entity ABC 31/12/2020DraftEntity ABCGBP test 202031/12/2020
Entity ABC 31/12/2019DraftEntity ABCGBP test 201931/12/2019
Entity DEF 30/06/2021DraftEntity DEFUSD test 202130/06/2021
Entity DEF 30/06/2020DraftEntity DEFUSD test 202030/06/2020
Entity DEF 30/06/2019DraftEntity DEFUSD test 201930/06/2019

 

Second tab: "Draft position"

IDHeading 1Heading 2Heading 3Heading 4Heading 5
Entity ABC 31/12/202199,999100,122100,245100,368100,491
Entity ABC 31/12/202098,99999,12299,24599,36899,491
Entity ABC 31/12/201997,99998,12298,24598,36898,491
Entity DEF 30/06/2021-2,0004,000-6,000-8,00010,000
Entity DEF 30/06/2020-1,0002,000-3,000-4,0005,000
Entity DEF 30/06/2019-5001,000-1,500-2,0002,500

 

 

 

As you can see, the visuals in the "Current selected year" column is working correctly however I am struggling to find the correct formula for the values in the "Prior year" column (circled in screenshot below in red) to produce the correct results. The prior year results should always be the current selected year minus 1 year. For example if the current selected year in the "Period End" slicer is 2021, then the Prior Year data should show for 2020 for the specific entity selected. 

 

Currently the Prior Year is showing the same as the Current selected year column which is incorrect. Many thanks in advance for your help!

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi ATYB9 ,

    I updated your sample pbix file, please find the detailed steps in the attachment.

    1. Unpivot Heading1~Heading5 columns of the query 'Merge1'

    2. Create a period dimension table(Don't create any relationship with Merge1 table)

    3. Update the formula of measure [SelectedYear] as below

    SelectedYear = SELECTEDVALUE('Period Ends'[Period End])

    4. Create two measures to get the selected year and previous year heading values

    CY_Headings =
    CALCULATE (
        SUM ( 'Merge1'[Value] ),
        FILTER ( 'Merge1', 'Merge1'[Period End] = [SelectedYear] )
    )
    PY_Headings = 
    CALCULATE (
        SUM ( 'Merge1'[Value] ),
        FILTER ( 'Merge1', 'Merge1'[Period End] = [PriorYearToSelectedYear] )
    )

    PS: After you open the attachment, please update the data source file directory with yours for the query "Summary details" and "Draft position"...

    Best Regards

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ATYB9 ,

    I updated your sample pbix file, please find the detailed steps in the attachment.

    1. Unpivot Heading1~Heading5 columns of the query 'Merge1'

    2. Create a period dimension table(Don't create any relationship with Merge1 table)

    3. Update the formula of measure [SelectedYear] as below

    SelectedYear = SELECTEDVALUE('Period Ends'[Period End])

    4. Create two measures to get the selected year and previous year heading values

    CY_Headings =
    CALCULATE (
        SUM ( 'Merge1'[Value] ),
        FILTER ( 'Merge1', 'Merge1'[Period End] = [SelectedYear] )
    )
    PY_Headings = 
    CALCULATE (
        SUM ( 'Merge1'[Value] ),
        FILTER ( 'Merge1', 'Merge1'[Period End] = [PriorYearToSelectedYear] )
    )

    PS: After you open the attachment, please update the data source file directory with yours for the query "Summary details" and "Draft position"...

    Best Regards

  • Sorry forgot to thank you for this! It was very much appreciated!