Forum Discussion

ParkJE1101's avatar
ParkJE1101
New Member
5 years ago
Solved

Show Gap in Pivot table

Dear Experts,

I want to show sales gap in pivot table in Power Bi. 

 

Raw data is as below.

FYCategprySales
FY20A10
FY20A5
FY20B20
FY20B30
FY21A20
FY21A30
FY21B10
FY21B10

 

And I want to show in Power BI Pivot table as below.

Showing FY20, FY21 sales is simple, but difficult to show sales gap between FY(FY21 vs. FY20)

CategoryFY20FY21FY21 vs. FY20
A155035
B5020-30

 

  • Hi, ParkJE1101 

     

    Try to create 3 measures like below:

    _FY20 =
    CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', 'Table'[FY] = "FY20" ) )
    
    _FY21 =
    CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', 'Table'[FY] = "FY21" ) )
    
    _FY21_20 =
    SUMX ( 'Table', [_FY21] - [_FY20] )
    

    Then to create a calculate table below:

    Table 2 =
    SUMMARIZE (
        'Table',
        'Table'[Category],
        "FY20", 'Table'[_FY21],
        "FY21", ' Table '[_FY21],
        "FY21-20", ' Table '[_FY21_20]
    )
    

    Result:

    OR:

    To do it in power query:

    1. Create a table copy
    2. then group by year and category,
    3. pivot table,
    4. finally add a custom column(FY21-FY20)

    Please refer to the attachment below for details

     

     

    Is this the result you want? Hope this is useful to you

    Please feel free to let me know If you have further questions

     

    Best Regards,
    Community Support Team _ Zeon Zheng
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • ParkJE1101 , You need to create three measures. And this case better to have a separate FY Table

     

    like

    FY 20 = calculate(sum(Table[Sales]), filter(Table,Table[FY] ="FY20"))

    FY 21 = calculate(sum(Table[Sales]), filter(Table,Table[FY] ="FY21"))

    diff = [FY 21] -[FY 20]

     

    or

     

    FY 20 = calculate(sum(Table[Sales]), filter(all(FY),FY[FY] ="FY20"))

    FY 21 = calculate(sum(Table[Sales]), filter(all(FY),FY[FY] ="FY21"))

    diff = [FY 21] -[FY 20]

     

     

    if you have a date use time intelligence

    Power BI — Year on Year with or Without Time Intelligence
    https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
    https://www.youtube.com/watch?v=km41KfM_0uA

  • Hi, ParkJE1101 

     

    Try to create 3 measures like below:

    _FY20 =
    CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', 'Table'[FY] = "FY20" ) )
    
    _FY21 =
    CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', 'Table'[FY] = "FY21" ) )
    
    _FY21_20 =
    SUMX ( 'Table', [_FY21] - [_FY20] )
    

    Then to create a calculate table below:

    Table 2 =
    SUMMARIZE (
        'Table',
        'Table'[Category],
        "FY20", 'Table'[_FY21],
        "FY21", ' Table '[_FY21],
        "FY21-20", ' Table '[_FY21_20]
    )
    

    Result:

    OR:

    To do it in power query:

    1. Create a table copy
    2. then group by year and category,
    3. pivot table,
    4. finally add a custom column(FY21-FY20)

    Please refer to the attachment below for details

     

     

    Is this the result you want? Hope this is useful to you

    Please feel free to let me know If you have further questions

     

    Best Regards,
    Community Support Team _ Zeon Zheng
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.