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
tonyclifton
Helper III
Helper III

Percentage Calculation of Matrix Total Row

Hello community,

I am trying to get the percentage calculation for the total row of my calculated column "KPI Dev %" right.
The below calculation is correct for each row however for the total row I want to divide the total of KPI DEV by KPI_act.

Background: I have to compare each calendar week to the previous one and calculate the deviation between two weeks.

 

KPI DEV = 
VAR PreviousRow =
    TOPN (
        1,
        FILTER (
            'Table',
              'Table'[CalendarWeek] < EARLIER ('Table'[CalendarWeek]) &&
                 'Table'[YearMonth] = EARLIER ( 'Table'[YearMonth])
                 && 'Table'[Company] = EARLIER ( 'Table'[Company])
        ),
        [CalendarWeek], DESC
    )
VAR PreviousValue =
    MINX ( PreviousRow, [KPI_act] )
RETURN 'Table'[KPI_act] - PreviousValue

 

 

"KPI DEV %" = same as KPI DEV but different return: RETURN CALCULATE(DIVIDE( SUM('Table'[KPI DEV]), PreviousValue))


So in below example for week 38 instead of Sum or Average function over those three rows this is my desired calculation:
Total of (KPI DEV / KPI_act) => 362/22563 = 1,604%

tonyclifton_0-1601047790267.png

Do you have an idea how this can be achieved?

Here's my raw table data:

YearMonthCompanyCalendarWeekKPI_act
01.09.2020 00:00:00Company A3711467
01.09.2020 00:00:00Company A3811697
01.09.2020 00:00:00Company B379607
01.09.2020 00:00:00Company B389742
01.10.2020 00:00:00Company A3711702
01.10.2020 00:00:00Company A3811823
01.10.2020 00:00:00Company B379528
01.10.2020 00:00:00Company B389793
01.09.2020 00:00:00Company C371127
01.09.2020 00:00:00Company C381124
01.10.2020 00:00:00Company C37975
01.10.2020 00:00:00Company C38874


Thank you.

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@tonyclifton, Based on what I have.

For Week-to-Week Better to Create a Week Range on the Start Date of the Week at Week of the Year

Year Week to [Year]*100 + [Week]

Column

Rango de la semana - RANKX (all('Date'),'Date'[Week Start date],,ASC,Dense)

Medida
Esta semana: CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]-max('Date'[Week Rank])))
Last Week ? CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]-max('Date'[Week Rank])-1))

refer to the blog

https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

View solution in original post

2 REPLIES 2
Icey
Community Support
Community Support

Hi @tonyclifton ,

 

Please refer to this post: Power BI: Totals Incorrect.

 

 

Best Regards,

Icey

 

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

amitchandak
Super User
Super User

@tonyclifton, Based on what I have.

For Week-to-Week Better to Create a Week Range on the Start Date of the Week at Week of the Year

Year Week to [Year]*100 + [Week]

Column

Rango de la semana - RANKX (all('Date'),'Date'[Week Start date],,ASC,Dense)

Medida
Esta semana: CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]-max('Date'[Week Rank])))
Last Week ? CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]-max('Date'[Week Rank])-1))

refer to the blog

https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

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.