Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Orstenpowers
Post Patron
Post Patron

Difference in total and relative; also for cumulative figures

Dear all,

 

Based on Nate Chamberlain’s “DataKey” I prepared the below visual for which I used the following data:

“DateKey”[Month]

“DateKey”[Month]

“Data”[AmountEUR]

 

PBI_V.JPG

Is it possible to leave the column “Gesamt”?


Now I do need further measures and don’t know how to handle.

  1. Instead of Gesamt I would like to see difference (total and relative) between 2020 and 2021 by month.
  2. Cumulative figures
  3. Difference (total and relative) between 2020 and 2021 for the cumulative figures

I think for the specialists our there this is very easy, but I do not get it. Even when trying to adapt posted solutions, I do not get it worked…

 

1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @Orstenpowers 

 

To create a measure like this:

 

_total = 
var _21=    
CALCULATE (
        SUM ( [value] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[MMM] ), [Year] = 2021 )
    )
var _20=
CALCULATE (
            SUM ( [value] ),
            FILTER ( ALLEXCEPT ( 'Table', 'Table'[MMM] ), [Year] = 2020 )
        )
return 
IF (
    ISINSCOPE ( 'Table'[Year] ),
    SUM ( [value] ),
    IF(ISBLANK(_21),_20,_21-_20)
)

 

Cumulative figures:

Cumulative figures = 
var _c21=    
    CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[Year]=2021&&'Table'[Date]<=MAX('Table'[Date])))
var _c20=
    CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[Year]=2020&&MONTH('Table'[Date])<=MONTH(MAX('Table'[Date]))))
var _cumulative=
    CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[Year]=MAX('Table'[Year])&&'Table'[Date]<=MAX('Table'[Date])))
var _21=    
    CALCULATE (SUM ( [value] ),FILTER ( ALLEXCEPT ( 'Table', 'Table'[MMM] ), [Year] = 2021 ))
var _20=
    CALCULATE (SUM ( [value] ),FILTER ( ALLEXCEPT ( 'Table', 'Table'[MMM] ), [Year] = 2020 ))
return 
IF (
    ISINSCOPE ( 'Table'[Year] ),
    _cumulative,
    IF(HASONEVALUE('Table'[MMM]),IF(ISBLANK(_21),BLANK(),_c21-_c20),_21-_20)
)

Sample:

vangzhengmsft_1-1630315060171.png

Result:

vangzhengmsft_0-1631006057222.png

Please refer to the attachment below for details. Hope this helps.

 

 

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.

View solution in original post

3 REPLIES 3
v-angzheng-msft
Community Support
Community Support

Hi, @Orstenpowers 

 

To create a measure like this:

 

_total = 
var _21=    
CALCULATE (
        SUM ( [value] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[MMM] ), [Year] = 2021 )
    )
var _20=
CALCULATE (
            SUM ( [value] ),
            FILTER ( ALLEXCEPT ( 'Table', 'Table'[MMM] ), [Year] = 2020 )
        )
return 
IF (
    ISINSCOPE ( 'Table'[Year] ),
    SUM ( [value] ),
    IF(ISBLANK(_21),_20,_21-_20)
)

 

Cumulative figures:

Cumulative figures = 
var _c21=    
    CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[Year]=2021&&'Table'[Date]<=MAX('Table'[Date])))
var _c20=
    CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[Year]=2020&&MONTH('Table'[Date])<=MONTH(MAX('Table'[Date]))))
var _cumulative=
    CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[Year]=MAX('Table'[Year])&&'Table'[Date]<=MAX('Table'[Date])))
var _21=    
    CALCULATE (SUM ( [value] ),FILTER ( ALLEXCEPT ( 'Table', 'Table'[MMM] ), [Year] = 2021 ))
var _20=
    CALCULATE (SUM ( [value] ),FILTER ( ALLEXCEPT ( 'Table', 'Table'[MMM] ), [Year] = 2020 ))
return 
IF (
    ISINSCOPE ( 'Table'[Year] ),
    _cumulative,
    IF(HASONEVALUE('Table'[MMM]),IF(ISBLANK(_21),BLANK(),_c21-_c20),_21-_20)
)

Sample:

vangzhengmsft_1-1630315060171.png

Result:

vangzhengmsft_0-1631006057222.png

Please refer to the attachment below for details. Hope this helps.

 

 

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.

amitchandak
Super User
Super User

@Orstenpowers , you have to use isinscope to switch total with diff ,

 

refer My example, I have used date table and time intelligence

 

Diff = if(not(isinscope(Date[Year])), SUM(Sales[Sales Amount]) - Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year)) ,SUM(Sales[Sales Amount]))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak 

Thanks for your feedback!
What do you mean with "My example"? 🤔

 

The formula you mentioned, this is a measure?

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.